Conditional / If Statements not running
Show older comments
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 Comments
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
on 26 Feb 2016
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
on 26 Feb 2016
Laura Moylan
on 26 Feb 2016
Accepted Answer
More Answers (0)
Categories
Find more on Variables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!