how to program to check the sequence 0<alpha1<a​lpha2<alph​a3<alpha4<​pi/2

2 ビュー (過去 30 日間)
Mudasir Ahmed
Mudasir Ahmed 2015 年 6 月 25 日
コメント済み: Mudasir Ahmed 2015 年 6 月 26 日
hi.
i have written a program in which 4 angles are derived (alpha1, alpha2, alpha3,alpha4). now i have to check whether they are in sequence or not. if not then i have to find again these angles. kindly help me how i program it to verify above condition. thanks in advance
Regards

採用された回答

Stephen23
Stephen23 2015 年 6 月 25 日
編集済み: Stephen23 2015 年 6 月 25 日
MATLAB supports binary relational operators only, so one cannot chain comparisons together as a<b<c, this needs to be written as a<b & b<c. You might want something like this:
val = 0<alpha1 && alpha1<alpha2 && alpha2<alpha3 && alpha3<alpha4 && alpha4<pi/2;
  4 件のコメント
Stephen23
Stephen23 2015 年 6 月 25 日
編集済み: Stephen23 2015 年 6 月 25 日
I assume that the rows are supposed to be different, and not simply repeated like this? In any case, a true general solution would be to use diff, like this:
>> A = [0,15,30,45,60; 1,2,3,4,5; 0,45,90,135,180]
A =
0 15 30 45 60
1 2 3 4 5
0 45 90 135 180
>> all(0<diff(A,1,2),2)
ans =
1
1
1
Now change the last value of the second row:
>> A = [0,15,30,45,60; 1,2,3,4,1; 0,45,90,135,180]
A =
0 15 30 45 60
1 2 3 4 1
0 45 90 135 180
>> all(0<diff(A,1,2),2)
ans =
1
0
1
This is the most general solution in that it works for input matrices of any size.
Mudasir Ahmed
Mudasir Ahmed 2015 年 6 月 26 日
thanks sir. :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by