필터 지우기
필터 지우기

Putting random values in for loop

조회 수: 3 (최근 30일)
SAZZAD HOSSAIN
SAZZAD HOSSAIN 2012년 10월 24일
Hi everyone
I am writing a program in which i am using the following loop.
for t = 1:1:81;
vv(t) = floor(+1*120*sin(2*pi*(t-1)/40));
end
The vales of vv are like 0,18,37...... However, i found that my program has some instability due to jumping directly from vv = 0 to vv = 18. Therefore, my intention is to keep the inputs for the loop as it is (otherwise it gets too long to run), but to put few more input values for vv. for example I want to start with 0, 1, 5, 9, 14, 18,37,....... Hence i need to put those 4 values in between 0 and 18 to bring stability into the result. Can anyone please help me.
Thanks in advance
Hossain

채택된 답변

Jonathan Epperl
Jonathan Epperl 2012년 10월 24일
Do what Matt suggested:
VV = floor(+1*120*sin(2*pi*(t-1)/40));
Then add your extra values into VV:
VV = [VV(1) 1 5 9 14 VV(2:end)];
Then run your loop
for i=1:numel(vv) % presumably 85
vv = VV(i);
% your other code
end
  댓글 수: 1
SAZZAD HOSSAIN
SAZZAD HOSSAIN 2012년 10월 24일
Thanks Jonathan. Works perfect.

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

추가 답변 (1개)

Matt Kindig
Matt Kindig 2012년 10월 24일
Hi Sazzad,
First of all, you don't need the loop: you can just do it like this:
vv = floor(+1*120*sin(2*pi*(t-1)/40));
Second, can you just use a finer resolution of t, such as:
t= 1:0.1:81;
vv = floor(+1*120*sin(2*pi*(t-1)/40));
Now vv changes from 0 to 1 to 3 to 5, etc.
  댓글 수: 1
SAZZAD HOSSAIN
SAZZAD HOSSAIN 2012년 10월 24일
Hi Matt
Thanks for the answer. The vv = floor (....) part is followed by a lot of other codes and it needs to be in a for loop. And i cannot use finer resolution. the current resolution i am using takes around 2 days to complete so i kind of want to stick to this resolution.
Thanks.

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

카테고리

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