xlsread with file names in arrays

I have 3 excel files with following names
'Input1.xls'
'Input2.xls'
'Input3.xls'
Is there a way to define an array such as:
InputFiles={'Input1.xls' 'Input2.xls' 'Input3.xls'}
so that I can write a loop where each file name is called based on its index:
for i=13
datax=xlswrite(InputFiles(i))
end
I try this exactly as i just wrote but for some reason Matlab doesn't accept it.

댓글 수: 1

It would help if you typed your example correctly,
I assume
for i = 13
is meant to be
for i = 1:3
and
data=xlswrite(...
is meant to be
data=xlsread(...
In what way matlab does not accept your code?

댓글을 달려면 로그인하십시오.

답변 (1개)

Guillaume
Guillaume 2017년 3월 15일

0 개 추천

Other than the many typos and the wrong brackets used to index the cell array, the main issue I can see with your code is that you constantly overwrite the same output, so at the end of the loop, you're only left with the content of the last file. This would fix this:
InputFiles = {'Input1.xls', 'Input2.xls', 'Input3.xls'};
Data = cell(size(InputFiles)); %preallocate output cell array for efficiency
for i = 1 : numel(InputFiles) %don't hardcode the end of the loop when you can just ask matlab for the value
Data{i} = xlsread(InputFiles{i}); %use {} to access the content of a cell
end

카테고리

도움말 센터File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

질문:

2017년 3월 15일

답변:

2017년 3월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by