Hi,
I'm struggling a lot with a small part of my code, hope someone could help me out with it.
Basically, on the first elseif step, I want to add values from a matrix called Table2 when t>24, but I'm only getting values from the first if, which makes no sense to me.
y = 8;
x = 24;
for t = 9:48;
if t <= x
Temp_v(t) = Table(t,6) + Table2(t-y,6) - Table(t-y,6);
elseif x < t <= x+y
Temp_v(t) = Table(t,6) + Table2(t-8,6) - Table(t-8,6)+ Table(t-24,6) - Table2(t-x,6);
else
Temp_v(t) = Table(t,6) + Table2(t-y,6) - Table(t-y,6)+ Table(t-x,6) - Table2(t-x,6)+ Table2(t-(x+y),6) - Table(t-(x+y),6);
end
end
Thanks!

 채택된 답변

Adam Danz
Adam Danz 2019년 9월 1일
편집: Adam Danz 2019년 9월 1일

0 개 추천

This
x < t <= x+y
should be
(x < t) && (t <= x+y)
Here's a demo that shows why the first line fails.
% This returns TRUE even though 5 is not less than 4
5 < 4 <= 8+1
% The reason is that the left side is evaluated first
5 < 4 % = false(0)
0 <= 8+1 % = true

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2019년 9월 1일

댓글:

2019년 9월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by