How can I associate Excel header names as column variables when using XLSREAD?

21 views (last 30 days)
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
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

More Answers (0)

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2006b

Community Treasure Hunt

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

Start Hunting!