Conditional / If Statements not running
이전 댓글 표시
I have a code as follows:
Thresh=250;
if(Difference(:,1)>Thresh)
disp('Seizure')
else
disp('Nil')
if(Difference(:,2)>Thresh)
disp('Seizure')
else
disp('Nil')
if(Difference(:,3)>Thresh)
disp('Seizure')
else
disp('Nil')
if(Difference(:,4)>Thresh)
disp('Seizure')
else
disp('Nil')
if(Difference(:,5)>Thresh)
disp('Seizure')
else
disp('Nil')
if(Difference(:,6)>Thresh)
disp('Seizure')
else
disp('Nil')
if(Difference(:,7)>Thresh)
disp('Seizure')
else
disp('Nil')
if(Difference(:,8)>Thresh)
disp('Seizure')
else
disp('Nil')
end
end
end
end
end
end
end
end
It seems to stop running when 'Seizure' is returned for the first time. E.g. if seizure is returned on the third if, it does not return me anything for the remaining 5 ifs. Any help or suggestions would be greatly appreciated!! :)
댓글 수: 4
Please format your code in a {} Code block as it is very difficult to read in that format!
It would also be useful to see your data though - what is in Difference(:,1:8) and what size is Difference?
If Difference(:,1) is returning multiple values (i.e. you have a true 2d matrix) then your > comparison may also not be doing what you expect it to as a logical comparison.
Angelo
2016년 2월 26일
Hi Laura,
it works properly. When the statement is satisfied (in your case after the third value of Difference, for ex. for Difference = [249:1:256]; ) then if statement is concluded. If you want to check all the values of the Difference array you can use a For cycle:
Difference = [248:1:255];
Thresh=250;
for i = 1:length(Difference)
if (Difference(:,i)>Thresh)
disp(['Element ',num2str(i),' Seizure'])
else
disp(['Element ',num2str(i),' Nil'])
end
end
Best regards
angelo
Laura Moylan
2016년 2월 26일
Laura Moylan
2016년 2월 26일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Variables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!