Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
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'?

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 28 de Sept. de 2021
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

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by