Filter löschen
Filter löschen

xlsread and its output argument in a for loop

2 Ansichten (letzte 30 Tage)
Hsinho Huang
Hsinho Huang am 8 Jan. 2017
Bearbeitet: Stephen23 am 8 Jan. 2017
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

Akzeptierte Antwort

Stephen23
Stephen23 am 8 Jan. 2017
Bearbeitet: Stephen23 am 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

Weitere Antworten (0)

Kategorien

Mehr zu Scripts finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by