save result in cell

1 Ansicht (letzte 30 Tage)
NA
NA am 14 Mär. 2019
Bearbeitet: madhan ravi am 14 Mär. 2019
I have a for loop (4 iteration) and A is changing in each loop.
A in first loop (for example) A=[106]
A in second loop A=[];
A in third loop A=[4;31;55;60;97;107];
A in 4th loop A=[7,8,30;70];
I mean size of A is changing in each loop but it is column vector.
I want to save result of A in each loop.
result should be
result={[106],[],[4;31;55;60;97;107],[7,8,30;70]}

Akzeptierte Antwort

madhan ravi
madhan ravi am 14 Mär. 2019
Bearbeitet: madhan ravi am 14 Mär. 2019
% 7;8;30
% ^ ^---- as you say column vector
A=cell(1,4);
for k=1:4
A{k}=...;
end

Weitere Antworten (1)

Raghunandan V
Raghunandan V am 14 Mär. 2019
Bearbeitet: Raghunandan V am 14 Mär. 2019
create a cell and then store them. Dont create the matrix at all
result = cell(1,n)
for k = 1:n
result{k} = 106 ;%<calculate the value to be stored>
end

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by