How Can i import data from excel with column names

I am looking to import data from excel with colum names. I also meed to perform calculations for the whole column with that name.
For Example: Say i have a excel sheet with 50 columns of data. I want to pick a column from the dataset with the name of the column and do some mathematical operations on the whole column.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 11 de Abr. de 2016

0 votos

If you have R2013b or later then I recommend you use readtable() and then operate on the column by name.

5 comentarios

Thanks for your answer but after i read the excel workbook i am not able to use the column name to do any operation?
t = readtable('Dataset Stat Project2.xlsx');
X = t.GPA * 10;
Thanks a lot Walter for the solution......That solved a part of my problem.
I am attaching an other image of the other data-set i am working on and having an issue. Please have a look and let me know if you can find a way to do those.
Walter Roberson
Walter Roberson el 12 de Abr. de 2016
Editada: Walter Roberson el 12 de Abr. de 2016
I cannot read the names of your columns in your excel data. What I can read, together with the warning message, suggests that you have multiple columns with the same header, so it might have modified the name of the variables to prevent duplicates.
To see the names that were used for the columns, use
t.VariableNames
t = readtable('MAE 525 HW5 Soln.xlsx', 'Range', 'B15:V12006');
t.Properties.VariableNames
CO2_meas = str2double(t.CO2_meas(2:end));
Your data turns out to have a 14 irrelevant lines at the top that needed to be skipped over. Unfortunately readtable() does not support the HeaderLines option for spreadsheets in the release I have (R2014a), but the change in documentation for R2014b suggests that for that version onward you might possibly be able to use
t = readtable('MAE 525 HW5 Soln.xlsx', 'HeaderLines', 14);
You might notice I have used str2double on the data. That is because you have a second header below the row name that gives the units, and that text field is being interpreted by readtable as indicating that the entire column should be treated as text. :(

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 11 de Abr. de 2016

Comentada:

el 13 de Abr. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by