Add new double array within cell for each iteration in a for loop

I'm trying to get many values out of an excel sheet.
Is it possible to have a cell variable which gets added one more array of double values for each iteration, and how do i write it?
Outside a for loop i can write:
hourValues{1} = some code;
hourValues{2} = some code;
hourValues{3} = some code;
and i will get a 1x3 cell named hourValues which with some code will contain my 3 arrays of double. But how to write this inside a for loop?

 Réponse acceptée

hourValues=cell(1,3);
for i=1:3
hourValues{i} = some code;
end

3 commentaires

Thanks for reply. Then i guess my problem is in the way i use String. For some reason i don't get any error.
When the code:
hourValues{1} = some code(raw(:,3),['1']);
hourValues{2} = some code(raw(:,3),['2']);
hourValues{3} = some code(raw(:,3),['3']);
is written like that (outside any for loop) i get:
But when writing inside a for like this:
for i=1:3
text = string(i);
hourValues{i} = some code(raw(:,3),[text]);
end
i just get this:
How should i pass the string to get it to work?
(Or could the problem be elsewhere?)
There is something weird with the code i use. No matter how i pass the string it doesn't work, so i will have to open a separate question on that. You've answered my questions Matt J, thank you. :)
string() works by the way, and strangely num2str gave me char. Example, this code:
a = 1;
b = string(a);
c = num2str(a);
returns this:

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide 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