MATLAB Answers

Extract Data From Imported Excel Sheet Containing Specific Numeric Values

12 views (last 30 days)
James Metz
James Metz on 31 Jan 2021
Answered: dpb on 1 Feb 2021
Hi all. I have imported a large 655x6 data set from excel onto MATLAB and am now trying to extract certain data from the table. The data has a column titled "gender" where male is denoted by a 1 and female by a 0. I want to create two separate arrays: one with all the females, and one with all the males. The arrays need to also contain all additional information in the row associated with each male or female (i.e. their height, ID, FEV, etc.). I sifted through the MathWorks help page about data sets, but I am not too good with syntax. Can anyone help?
This is how the spreadsheet is set up:
ID Height FEV Gender Smoker etc......
1 123 70 63 0 1
2 456 63 102 1 0

Accepted Answer

dpb on 1 Feb 2021
Rather than duplicating the same data in multiple places, use grouping variables to process the data by the desired categories/groups. See for a very similar type of dataset example.
NB that if you use the table instead of an array you get the benefit if handling disparate data types together (where in your data Gender, Smoker are prime categorical variables), you can do this with rowfun.
I just pointed another Q? in the same direction <here>

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by