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

3 次查看(过去 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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by