Inequality problem

12 ビュー (過去 30 日間)
Synchronie
Synchronie 2012 年 1 月 21 日
Hi.... Does the following inequality work on Matlab:
for col=1:1:num_cols
if (0.00>(real_qn1(col))<0.25)
real_c(col)=(1/sqrt(2));
else if (0.25>(real_qn1(col))<0.50)
real_c(col)=(-1/sqrt(2));
else if (0.50>(real_qn1(col))<0.75)
real_c(col)=(-sqrt(2));
else if (0.75>(real_qn1(col))<1.00)
real_c(col)=(sqrt(2));
end
end
end
end
end
I tried it.. But it's giving me inverted results..
Thank you

採用された回答

Dr. Seis
Dr. Seis 2012 年 1 月 21 日
You have to split them up... instead of:
A < X < B
you have to do:
(A < X) && (X < B)
Incidentally, make sure you are using good logic. At your first if you have:
0.00 > X < 0.25
which is the same(*) as saying:
(X < 0.0) && (X < 0.25)
The second part is redundant, because if X is less than 0.0 it is also less than 0.25
(*) By saying "same" I mean the way you would interpret the statement. Matlab executes those two statements very differently.
  3 件のコメント
Walter Roberson
Walter Roberson 2012 年 1 月 21 日
"else if" with a space is valid; it just requires one more "end" than otherwise.
Dr. Seis
Dr. Seis 2012 年 1 月 21 日
I am not arguing against it because it is not valid, I am arguing against it because it is not efficient (from a code writing/reading standpoint).

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

その他の回答 (1 件)

Synchronie
Synchronie 2012 年 1 月 22 日
Thanks a lot for your suggestions.. I paid attention to the inequality sign and used elseif(without space) and it worked perfectly well..

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by