Azzera filtri
Azzera filtri

xlsread and its output argument in a for loop

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Stephen23
Stephen23 il 8 Gen 2017
Modificato: Stephen23 il 8 Gen 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

Più risposte (0)

Categorie

Scopri di più su Scripts in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by