How to save the values after each iteration in a matrix ?

조회 수: 14 (최근 30일)
Reema Alhassan
Reema Alhassan 2018년 7월 13일
댓글: Stephen23 2023년 5월 25일
Hello everybody ,
I did some calculation in a loop and this is the output I need to put the value after each iteration in Nx1 matrix how can I do this?
sumOfValues1 =
'787226.437500'
sumOfValues1 =
'162571.843750'
sumOfValues1 =
'257137.468750'
sumOfValues1 =
'366862.625000'

채택된 답변

Adam Danz
Adam Danz 2018년 7월 13일
편집: Adam Danz 2018년 7월 13일
Follow this example for n=6 loops where I store your sumOfValues1 in a n-by-1 vector. Also, take some time to read through this document so you understand how indexing works.
% initialize variable
n = 6;
a = zeros(n,1);
% Loop through and store result
for i = 1:n
a(i) = sumOfValues1;
end
  댓글 수: 12
Priteesh Ranjan
Priteesh Ranjan 2023년 5월 25일
How to store values if
for i = 1:0.01:1
its giving error Array indices must be positive integers or logical values which is very obvious as indices now wont be integral
Stephen23
Stephen23 2023년 5월 25일
@Priteesh Ranjan: in general with MATLAB it is easier to loop over indices rather than over data values:
V = 1:0.01:1; % data
for k = 1:numel(V) % indices
V(k)
..
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by