Effacer les filtres
Effacer les filtres

Loops for adding data

1 vue (au cours des 30 derniers jours)
Gurvinder
Gurvinder le 15 Août 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

Réponse acceptée

David Sanchez
David Sanchez le 15 Août 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 commentaire
Gurvinder
Gurvinder le 15 Août 2013
Thank you for your response.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by