Store all iteration loop outputs in a matrix

9 次查看(过去 30 天)
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

采纳的回答

Mischa Kim
Mischa Kim 2014-7-8
编辑:Mischa Kim 2014-7-8
UTS, use instead
m(i,:) = [i j k];
The output is an array m with 10 rows, 3 columns.
  9 个评论
Durga Aryal
Durga Aryal 2018-2-2
How did you solve the problem of subscripted dimension mismatch?
Ashish Kundaliya
Ashish Kundaliya 2019-4-5
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?!

请先登录,再进行评论。

更多回答(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