Store all iteration loop outputs in a matrix
조회 수: 8 (최근 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
댓글 수: 0
채택된 답변
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
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 Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!