for,if statements

조회 수: 6 (최근 30일)
Marcos Perez Rodriguez
Marcos Perez Rodriguez 2019년 10월 30일
댓글: Marcos Perez Rodriguez 2019년 10월 30일
I need to create a data vector that is 0 to 200 days in 0.1 increments and is 0 at all times except on days 10-30, 1 for days 10-30. I tried this and it didn't work. I think it has something to do with the "if ii = 1:length" part because if I use "if ii = t" it says "Array indices must be positive".
t = [0:0.1:200]; %Days with 0.1 sample spacing
for ii = 1:length(t)
if ii == 10.000:30.000
y1(ii) = 1;
else y1(ii) = 0;
end
end

채택된 답변

Walter Roberson
Walter Roberson 2019년 10월 30일
if ii >= 10 && ii <= 30
  댓글 수: 1
Marcos Perez Rodriguez
Marcos Perez Rodriguez 2019년 10월 30일
What if I wanted to keep that interval of 0.1? Because It works without that interval but when I do
for ii = 1:0.1:length(t)
it doesn't work.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by