필터 지우기
필터 지우기

xlsread and its output argument in a for loop

조회 수: 2 (최근 30일)
Hsinho Huang
Hsinho Huang 2017년 1월 8일
편집: Stephen23 2017년 1월 8일
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

채택된 답변

Stephen23
Stephen23 2017년 1월 8일
편집: Stephen23 2017년 1월 8일
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개)

카테고리

Help CenterFile Exchange에서 Scripts에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by