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 Center および File ExchangeDatabase Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by