Comparing two values of a matrice

1 vue (au cours des 30 derniers jours)
lui hellesoe
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
Guillaume
Guillaume le 11 Avr 2018
What is the age variable? Is it the chest pain?
lui hellesoe
lui hellesoe le 11 Avr 2018
So the age variable is the age of the patients. It scales from 29-79 years of age.
Chest pain scale from 1-4 (4 being most painful, 1 least painful)

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
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'})
For even more prettiness, you could change the sex variable to a categorical array:
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'})
See rowfun, varfun and splitapply for more ways to compute stats on a table.
  1 commentaire
lui hellesoe
lui hellesoe le 11 Avr 2018
Thanks for taking the time out of your day to help me. I appreciate it.

Connectez-vous pour commenter.

Plus de réponses (0)

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!

Translated by