store data after WHILE loop

4 ビュー (過去 30 日間)
Nadia Numa
Nadia Numa 2021 年 4 月 5 日
コメント済み: darova 2021 年 4 月 6 日
Hello.
I need some help to store values in MATLAB using the following code:
for n = 1:some number
iter = 0;
while % condition
iter = iter + 1 ;
for k = 1:9
% call the integrator 9 times
[t,s] = ode113(@(t,y) eqns, [0 t{k}], X{k}, options);
% X{k} contains 9 initial conditions where each has 6 values
x{k} = s(:,1:6)
% x{k} = stores each arc from integration
x = 1x9 cell array where each cell is #rowsx6
end
end
state(n,:) = x;
end
The issue I am having is that state does not have all n values of x. For example, if n = 2, state is size 2x9 BUT only the x values for n = 2 is stored; nothing is saved for n = 1. I also tried: state{n}(iter,:) inside the while loop and it also only stores the x data from the last iteration. It appears that the variable state is being overwritten.
Can someone please point me in the right direction? Thank you.

回答 (1 件)

Sara Boznik
Sara Boznik 2021 年 4 月 5 日
Try:
state(:,n)=x(:);
end
state=state(:,1:n)
  2 件のコメント
Nadia Numa
Nadia Numa 2021 年 4 月 6 日
Thank you!!!
darova
darova 2021 年 4 月 6 日

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by