필터 지우기
필터 지우기

how to inser loop in equations

조회 수: 1 (최근 30일)
Vedang Mhaske
Vedang Mhaske 2021년 5월 26일
댓글: Vedang Mhaske 2021년 5월 26일
clc;
pstep = 20;
freq = (1:5);
itime = freq;
for i=1:5
itime(i) = itime(i-1) +(1./ pstep.*freq(i))
end
I wanted to use freq as 1 to 5 and to start calculating time from itime(1) where itime(0)=0 and start this loop for each freq.

채택된 답변

Mathieu NOE
Mathieu NOE 2021년 5월 26일
hello
in matlab , index are starting with 1 (it's not a zero based language) - so your code will not work for i = 1
I made a few modifications :
  • changed the initialisation , assuming the general rules applies to th first sample itime as well (to be confirmed by you)
  • in the for loop , be aware that how you wrote +(1./ pstep.*freq(i)) means freq(i) is at the numerator side , not at the denominator. I guess this is not waht you wanted so I changed the parenthesis accordingly
% finally this is the code after some corrections :
clc;
pstep = 20;
freq = (1:5);
itime = freq;
itime(1) = 1./ (pstep.*freq(1)); % updated
for i=2:5 % updated
itime(i) = itime(i-1) +1./ (pstep.*freq(i)); % updated
end
  댓글 수: 1
Vedang Mhaske
Vedang Mhaske 2021년 5월 26일
Thank you for your valuable reply.

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

추가 답변 (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