Loops for adding data

1 visualización (últimos 30 días)
Gurvinder
Gurvinder el 15 de Ag. de 2013
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

Respuesta aceptada

David Sanchez
David Sanchez el 15 de Ag. de 2013
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 comentario
Gurvinder
Gurvinder el 15 de Ag. de 2013
Thank you for your response.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by