필터 지우기
필터 지우기

How to store values in an array from a for loop

조회 수: 8 (최근 30일)
Nickolas Vrvilo
Nickolas Vrvilo 2017년 10월 20일
답변: Shubhankar Poundrik 2020년 7월 3일
Hello, below is my code. I am trying to store the values of i after each iteration into the tseArray. For example, I am trying to store the first value, 730374, into the array, and then the next value, (730374+543.4) into the next value. However, I am having some trouble as I can't seem to figure out how to do it. I would really appreciate being shown how to do it or at least pushed in the right direction, thank you.
tseArray = zeros(1,150);
for i = 730374:543.4:811884
date(i) = 730374;
tseArray = date;
disp(tseArray)
end;
  댓글 수: 2
KSSV
KSSV 2017년 10월 20일
YOur tsearray always takes same value date i.e 730374..why loop needed? You need to think about what you are trying to ask/ do.
Cauli Vilela Ferreira
Cauli Vilela Ferreira 2020년 7월 2일
i want this same thing

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

답변 (1개)

Shubhankar Poundrik
Shubhankar Poundrik 2020년 7월 3일
Hi Nickolas,
I understand that you are trying to store an arithmetic progression in an array, and are not sure how to do it.
This can be done with one simple line of code
tseArray = 730374:543.4:811884
If for some reason, this has to be be done in a for loop, then it may be done in the following manner.
tseArray = zeros(1, 151);
counter= 1;
for i=730374:543.4:811884
tseArray(1, counter) = i;
counter = counter+1;
end
tseArray
Regards,
Shubhankar

카테고리

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