Conditional Scatter plotting based on third data set
Afficher commentaires plus anciens
The b[e]low matrix represents 5 people (columns) over time (each row is a year). I'd like to generate some script that, returns a vector, and says something along the lines of if the entire column is 1 (male), then that person is designated as 1, if the entire column is 3 (female that has never breastfed), then that person is designated as 3, if a column is a mix of 2 (female that has breastfed at some point) and 3, then designate that person at 2.
3 1 2 1 3
3 1 2 1 3
2 1 2 1 3
2 1 2 1 3
2 1 2 1 3
2 1 2 1 3
2 1 2 1 3
2 1 3 1 3
2 1 3 1 3
2 1 3 1 3
2 1 3 1 3
2 1 3 1 3
I'd like to have a vector returned that looks like this for the above example
sex = 2 1 2 1 3
Then, I would like to use this to add (NOT DONE YET) a condition to the following plot:
figure
scatter (Resident , MC_participant_Mean) %plot of duration of residency vs mean start of exposure
xlabel('Duration of residence in community (yr)')
ylabel('Mean start of Exposure after 1970 (yr)')
title('Start of exposure vs. years in community')
So if a person has a sex status of 1 (male), then plot their {scatter (Resident , MC_participant_Mean) } data points as green; if the sex status is 2, then red; if 3, then blue....I'd like to color-code the scatter plot based on the sex status of the study participant. Is this possible??
Thank you for your time and help!!
Réponse acceptée
Plus de réponses (1)
dpb
le 9 Juin 2021
>> SX=1*all(M==1)+2*(any(M==2)&any(M==3))+3*all(M==3)
SX =
2 1 2 1 3
>>
Create categorical variable from the coding; choose names at will--
>> SX=categorical(SX,[1:3],{'Male','Female YES','Female NO'})
SX =
1×5 categorical array
Female YES Male Female YES Male Female NO
>>
You can then use logical addressing to select appropriate subsets and plot as desired.
Catégories
En savoir plus sur Scatter Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!