How can I associate Excel header names as column variables when using XLSREAD?
21 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 27 Juin 2009
Commenté : Madhura Suresh
le 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.
Réponse acceptée
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
1 commentaire
Madhura Suresh
le 20 Nov 2014
@Tassie: Can you submit this to support@mathworks.com, and you can get direct assistance for this issue?
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!