필터 지우기
필터 지우기

how to process many sequential data using for loop

조회 수: 1 (최근 30일)
wasiu
wasiu 2014년 9월 1일
댓글: wasiu 2014년 9월 1일
I have 40 sequential data in my Workspace, and I would like to process each of all the 40 using a for loop.
the data is named like this...
trail
trail1
trial2
trial3
....
trial39
this is my code, but not working...
% Select each of the 40 trials
for e = 1:40
data = trial'e';
end;
so i need to process 'data' in each loop
thank you.
  댓글 수: 1
Adam
Adam 2014년 9월 1일
Does your data have to be named like that or do you have a choice? Does it comes from some external source with those names?
This is one of those regular questions that people come across (and I tried to do it myself once) the answer to which is pretty much always that you really don't want to organise your data in that way.
If you really want to then lookup 'eval' in the help, but ideally you should store your data differently, either as an n-dimensional matrix or as a single cell array of 40 elements.

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

채택된 답변

Iain
Iain 2014년 9월 1일
Ugh. Don't name variables like that, its a bad idea. But, the function you need is "eval"
current_trial = eval(['trial' num2str(e)]);
  댓글 수: 2
wasiu
wasiu 2014년 9월 1일
Thank you very much,it work. I will follow your advice next time, but i have a problem with the first trial,
if i use
for e=0:39
it gives error.... 'trial0' not found,
and if I use
for e=1:40 , it will skip the first 'trail'
please any advice, thank you.
wasiu
wasiu 2014년 9월 1일
i have solved the problem, thank you very much.
Thank you all

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

추가 답변 (1개)

Julia
Julia 2014년 9월 1일
Hi,
does this help you?
>> s=['trial','1']
s =
trial1
  댓글 수: 1
wasiu
wasiu 2014년 9월 1일
i need a for loop
example ...
for e = 1:40
data=['trial','e'];
% so i can get trail1 to trial40 as 'data', each trial in each loop, until I process of the 40
end;
thanks

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

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by