How can I associate Excel header names as column variables when using XLSREAD?
21 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Commented: Madhura Suresh
on 20 Nov 2014
I have an Excel file with columns of data. The top row has column names. When pulling into MATLAB using the XLSREAD function I would like to have variables created with the same name as the column headers which contain the column data.
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
This can be performed using a FOR loop and the EVALIN function
[mydata, myheader] = xlsread('Book1.xls');
for i = 1:length(myheader)
% compose a command to assign each column to a variable with the same
% name as the header
commandExec = [myheader{i}, ' = ', 'mydata(:,', num2str(i) , ');'];
% execute the composed command to actually create the variable
evalin('base', commandExec );
end
1 Comment
Madhura Suresh
on 20 Nov 2014
@Tassie: Can you submit this to support@mathworks.com, and you can get direct assistance for this issue?
More Answers (0)
See Also
Categories
Find more on Data Import from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!