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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Database Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by