xlsread and its output argument in a for loop
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am wondering how to code a for loop to have the respective outputs from reading the 3 Excel files.
[num1,txt1,raw1] = xlsread('D:\exp\data1.xlsx','sheet1','A5:F50');
[num2,txt2,raw2] = xlsread('D:\exp\data2.xlsx','sheet2','A5:F50');
[num3,txt3,raw3] = xlsread('D:\exp\data3.xlsx','sheet3','A5:F50');
I tried the following code but had an error 'Error: An array for multiple LHS assignment cannot contain M_STRING.'
for i=1:3
['num',num2str(i)','txt',num2str(i)','raw',num2str(i)'] = xlsread('D:\exp\data',num2str(i),'.xlsx','sheet',num2str(i)','A5:F50');
end
0 commentaires
Réponse acceptée
Stephen23
le 8 Jan 2017
Modifié(e) : Stephen23
le 8 Jan 2017
Don't do this. Read this to know why:
You should simply import the data into cell arrays and use indexing. This will be much faster and more robust:
N = 3;
Cnum = cell(1,N);
Ctxt = cell(1,N);
Craw = cell(1,N);
for k = 1:N
str = ['D:\exp\data',num2str(k),'.xlsx'];
[Cnum{k},Ctxt{k},Craw{k}] = xlsread(str,'sheet',num2str(k)','A5:F50');
end
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical 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!