How can I load multiple samples in a for loop

조회 수: 4 (최근 30일)
Shawna Bship
Shawna Bship 2015년 6월 24일
댓글: Joseph Cheng 2015년 6월 24일
I am trying to write a program that runs multiple samples but I can not figure out how to load a different sample for each iteration of the for loop.
For example:
sample1='/home/examplefilename.DTA';
sample2='/home/examplefilename2.DTA';
sample3='/home/examplefilename3.DTA';
q = inputdlg('How many samples were loaded?');
nsamples = str2double(q);
for h=1:nsamples;
[xd,yd,Pars]=eprload(sample(h));
xIndex = find(yd==max(yd(xd>=2600 & xd<=2850)), 1, 'first');
B = xd(xIndex);
v=Pars.MWFQ;
disp(sample(h))
end
This gives me the error message 'Undefined function or variable 'sample'.

채택된 답변

Joseph Cheng
Joseph Cheng 2015년 6월 24일
편집: Joseph Cheng 2015년 6월 24일
that is because sample is undefined but sample1 sample2 and sample3 is what you defined. how you're calling out that last line you should build sample{} as a cell array
sample{1}='/home/examplefilename.DTA';
sample{2}='/home/examplefilename2.DTA';
sample{3}='/home/examplefilename3.DTA';
q = inputdlg('How many samples were loaded?');
nsamples = str2double(q);
for h=1:nsamples;
%redacted
disp(sample(h))
end
  댓글 수: 1
Joseph Cheng
Joseph Cheng 2015년 6월 24일
and since we do this you don't need the inputdlg and you can get the size/length/numel of sample to calculate nsamples.

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

추가 답변 (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