"IF" condition not working with "<="

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 件のコメント

Rik
Rik 2020 年 5 月 29 日
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
Joyce Ai 2020 年 5 月 29 日
Thank you so so much this worked for me! Sorry about the question formatting, I wasn't aware of how to do that and thank you for editting it for me, I'll make sure to format it correctly next time. :) Thanks for your time!
Bjorn Gustavsson
Bjorn Gustavsson 2020 年 5 月 29 日
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.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStructures についてさらに検索

質問済み:

2020 年 5 月 29 日

コメント済み:

2020 年 5 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by