"IF" condition not working with "<="
Show older comments
I am trying to compare two sets of data. One stored as a 1x3 struct as Norm.Block(i).Rlong, the other as Norm.Block(i).Llong
My code is as follows:
for i=1:3
if Norm.Block(i).Rlong <= Norm.Block(i).Llong
Coact.Block(i).RlongLlong=Norm.Block(i).Rlong/Norm.Block(i).Llong;
elseif Norm.Block(i).Rlong>Norm.Block(i).Llong
Coact.Block(i).RlongLlong=Norm.Block(i).Llong/Norm.Block(i).Rlong;
end
end
When i try to run it, the code does not run and in the bottom left corner on MATLAB it just shows "busy". I think the problem is in the if statement but I'm not sure how to solve it.
I am very very new to this so someone please helpe me the solution seems simple but I just can't get it to work :(
Thank you in advance
3 Comments
Rik
on 29 May 2020
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable.
You can try putting a breakpoint at the start of your code and stepping through your code line by line. You can also step into a function call. That way you can make sure where your code hangs. It is very unlikely to be cause by the if or the comparison, however, you can verify this:
for i=1:3
a = Norm.Block(i).Rlong;
b = Norm.Block(i).Llong;
if a <= b
Coact.Block(i).RlongLlong=Norm.Block(i).Rlong/Norm.Block(i).Llong;
else
Coact.Block(i).RlongLlong=Norm.Block(i).Llong/Norm.Block(i).Rlong;
end
end
(the elseif can be replaced by else, as that condition is the exact opposite of the if)
Joyce Ai
on 29 May 2020
Bjorn Gustavsson
on 29 May 2020
The only case I can see where this loop would consume a large amount of time is if some of the Rlong and Llong fields have ended up as large enough arrays to make the Rlong/Llong produce a very big matrix.
Answers (0)
Categories
Find more on Structures 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!