How will my program read large data in a loop?

조회 수: 5 (최근 30일)
Prakriti Sardana
Prakriti Sardana 2015년 6월 16일
편집: Stephen23 2015년 6월 23일
I have data sets for about a 1000 objects. Each data set is a matrix with 'different no. of rows for each * 2 columns' as the matrix order. Now, I have called all the data sets in my current folder using:
files = dir('*.txt');
for i=1:length(files)
eval(['load ' files(i).name ' -ascii']);
end
which stores them as matrices X1, X2, et al. I need to assign each column of each matrix to a different variable for each, in a loop because writing separately for each object is not possible given the large number of data sets.
How do I do that?
  댓글 수: 1
Stephen23
Stephen23 2015년 6월 23일
편집: Stephen23 2015년 6월 23일
Avoid using eval for such trivial code. Learn to not use eval and your code will be more robust and easier to read.... Read this to know why:

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

채택된 답변

Walter Roberson
Walter Roberson 2015년 6월 16일
I suggest something like
files = dir('*.txt');
data = cell(length(files),2);
for i=1:length(files)
thisdata = load(files(i).name, '-ascii');
data{i,1} = thisdata(:,1);
data{i,2} = thisdata(:,2);
end
  댓글 수: 2
Prakriti Sardana
Prakriti Sardana 2015년 6월 23일
편집: Prakriti Sardana 2015년 6월 23일
Hm, thank you very much for your continued help.
Jan
Jan 2015년 6월 23일
@Prakriti Sardana: There is always a better solution than eval.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by