Store all iteration loop outputs in a matrix

8 visualizaciones (últimos 30 días)
UTS
UTS el 8 de Jul. de 2014
Comentada: Ashish Kundaliya el 5 de Abr. de 2019
clc;
a = 5;
b = 20;
for i = 1:10
j = (i + 25);
k = (j*b);
m =[i j k];
end
********************************
output:
m =
10 35 700
******************************************************************
Hi,
I am writing a program as mentioned above to store all iteration loop outputs in a matrix.
However, the output just displays the last iteration.
Could you please let me know the right code which is able to display all the iterations from 1 to 10.
Thank you very much

Respuesta aceptada

Mischa Kim
Mischa Kim el 8 de Jul. de 2014
Editada: Mischa Kim el 8 de Jul. de 2014
UTS, use instead
m(i,:) = [i j k];
The output is an array m with 10 rows, 3 columns.
  9 comentarios
Durga Aryal
Durga Aryal el 2 de Feb. de 2018
How did you solve the problem of subscripted dimension mismatch?
Ashish Kundaliya
Ashish Kundaliya el 5 de Abr. de 2019
Hey @durga aryal, you might be doing a mistake like if you haven't applied for loop then it will show exactly what you are asking for?!

Iniciar sesión para comentar.

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