Hi, I have a problem with a script given to me by my teacher , I don't know what is its point nor its problem

조회 수: 1 (최근 30일)
function A=einlesen(Anzahl)
% Einleseroutione
for i=1:Anzahl
name=sprintf('%i',i);
while length(name)<4, name=['0' name]; end
name=[name '.csv'];
A(:,:,i)=xlsread(name);
end

채택된 답변

Stephen23
Stephen23 2017년 9월 18일
편집: Stephen23 2017년 9월 18일
The function reads .CSV files into a numeric matrix. It uses a very awkward while loop to append leading zeros to the filename, to ensure that the name is atleast four characters long. The code then calls xlsread to get the data from some file.
The code is not well written. It would be better to:
  • Use sprint to generate the correct filename, complete with leading zeros:
>> sprintf('%04i.csv',1)
ans = 0001.csv
  • Preallocate the array that the data is being read into:
C = cell(1,Anzahl);
for k = 1:Anzahl
name = sprintf('%04i.csv',k);
C{k} = xlsread(name);
end
A = cat(3,C{:});
  댓글 수: 1
fatima-zahra achbah
fatima-zahra achbah 2017년 9월 18일
ok I see, my teacher gives me this and some XLS files and he told me to export all XLS file's data to a matrix in Matlab, and I have no clue how to do that since this my first time working in Matlab.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by