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

22 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 27 Juin 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

Plus de réponses (0)

Catégories

En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Produits


Version

R2006b

Community Treasure Hunt

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

Start Hunting!

Translated by