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!