フィルターのクリア

How to retrieve last entry of different array outputs for each loop?

3 ビュー (過去 30 日間)
Tanya Sharma
Tanya Sharma 2021 年 9 月 28 日
コメント済み: Mathieu NOE 2021 年 9 月 30 日
I have a function returning output as arrays of different lengths.
How can I retrieve the last entry of each array at each loop step?
Say for each loop entry
for a=1:1:10
the output array is of different lengths
xinit=0:0.1:1;
solinit=(xinit,[1 1 0]);
bvp4c=sol(@ode,@bcs,solinit); %%function odes contain the values of a and for each a the output has different lengths
v=sol.y(1,11);
fprintf('%g\n',v);
Now sol.y(1,11) will give me the last entry of my solution y.
But depending on variations in 'a', the array length changes.
So how do I print each last output for each 'a'?

採用された回答

Mathieu NOE
Mathieu NOE 2021 年 9 月 28 日
hello
if the solution (v) has variable length , you can do this
v=sol.y(1,:); % v is a vector of unknown length
fprintf('%g\n',v(end)); % print each last value of v
  2 件のコメント
Tanya Sharma
Tanya Sharma 2021 年 9 月 30 日
Thankyou for the help.
Mathieu NOE
Mathieu NOE 2021 年 9 月 30 日
My pleasure

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

その他の回答 (0 件)

カテゴリ

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