Comparing two values of a matrice
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
lui hellesoe
le 11 Avr 2018
Commenté : lui hellesoe
le 11 Avr 2018
The two columns: Sex(0 = female, 1 = male) Chest Pains(1 = low , 2 = normal , 3 = abnormal, 4 = high)
I tried to compare them using a histogram
hist(age,sex)
I get an error saying that I need unique xValues. I think this is due to Sex having the value 1 to represent male and also 1 represents chest pains for my other column.
Is there another way to compare two columns? My end goal is to see the males min, max and average chest pains (same for female).
4 commentaires
Réponse acceptée
Guillaume
le 11 Avr 2018
Ok, I'm a bit unclear why we have a variable for age but not one for chest pain in your question. Never mind, let's assume it's called chestpain.
The easiest is to first put all this information into a table, which also gives you prettier display:
patients = table(age(:), sex(:), chestpain(:), 'VariableNames', {'age', 'sex', 'chestpain'})
patients.sex = categorical(patients.sex, [0 1], {'F', 'M'})
Whether or not you do, does not matter for what follows up.
To calculate the min, max and average chest pain of a group, let's create a separate function for that. In its own chestpain_stats.m file:
function [minpain, maxpain, meanpain] = chestpain_stats(pain)
%pain: a column vector
minpain = min(pain);
maxpain = max(pain);
meanpain = mean(pain);
end
After that, calculating the stats per sex is simply:
patientstats = rowfun(@chestpain_stats, patients, 'GroupingVariable', 'sex', 'InputVariables', 'chestpain', 'OutputVariableNames', {'minpain', 'maxpain', 'meanpain'})
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Text Data Preparation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!