Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
Tanya Sharma
Tanya Sharma le 28 Sep 2021
Commenté : Mathieu NOE le 30 Sep 2021
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'?

Réponse acceptée

Mathieu NOE
Mathieu NOE le 28 Sep 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

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by