필터 지우기
필터 지우기

Loops for adding data

조회 수: 1 (최근 30일)
Gurvinder
Gurvinder 2013년 8월 15일
Hello Matlab community, if someone wouldn't mind helping me as i have very basic programming knowledge.
I have this bit of code:
for i = 1:150
STR = StatsSetHistory(i).DSAMPLES;
STR = cellmatrix2string(STR);
STR2 = [STR(i)];
% disp('STRING: ') % disp(STR) % disp('Hit a key to convert back to cell matrix...') % pause end
This is allowing me to collect all the names of samples via the function cellmatrix2string which i made.
What i need is help adding that each line of that 150 illeterations and storing it into a vector which i can hen pass into my database.
For example if the
illeteration 1 returns ==> sample
illeteration 2 returns ==> sample2
illeteration 3 returns ==> sample3
then i would like STR2 to contain
sample sample2 sample3 etc
thanks for your help in advance

채택된 답변

David Sanchez
David Sanchez 2013년 8월 15일
I would create a cell array with the sample data:
sample = cell(N_iter,1);
for k = 1:N_iter
% your_code_here
sample{k} = your_data_here;
end
Another way is to use eval, but it is highly recommended to use the first method.
for k = 1:N_iter
% your_code_here to create your_data
eval( sprintf('sample%s = %g',num2str(k), your_data') );
end
  댓글 수: 1
Gurvinder
Gurvinder 2013년 8월 15일
Thank you for your response.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by