I need to classify my result in catagories

1 回表示 (過去 30 日間)
Mahmoud Sami
Mahmoud Sami 2019 年 4 月 6 日
コメント済み: dpb 2019 年 4 月 6 日
I have this in my code
N=ones(1,numel(ma));
% ma is a matrix can be given from other equations.
N(ma==45 | ma==135)=0.5;
N(0< ma<45 | 45<ma<90)=1.5;
N(0< ma<45 | 45<ma<90)=1.5;
N(90<ma<135 | 135<ma<180)=1.5;
N(ma==0 | ma==180)=0;
N(ma==90)=1;
NA=N';
NN=sum(NA(:));
Pn=ones(1,numel(NN));
Pn(NN>5)= 100000;
Pn(NN==5)=100000;
Pn(NN<5)=1;
I had the pervious fcn, but is doesn’t work.
The results as
ma=[-35.2644,0,0,-45.0000,-45.0000,0,35.2644,54.7356,30.0000,45.0000,0,-45.0000,30.0000,-54.7356,-54.7356,-54.7356,-35.2644]
N=[1.5000,0,0,1.5000,1.5000,0,1.5000,1.5000,1.5000,1.5000,0,1.5000,1.5000,1.5000,1.5000,1.5000,1.5000]
In other words I want to say:-
If ma=45 or 135 (with negative or positive signs) make N =0.5
If ma=0 or 180 , make N =0
If ma=90 or 275 (with negative or positive signs) make N =1
Otherwise make N= 1.5
Then Pn like that
If NN>or =5 make Pn=100000
If NN<5 Make Pn=1

採用された回答

Star Strider
Star Strider 2019 年 4 月 6 日
Try this:
ma=[-35.2644,0,0,-45.0000,-45.0000,0,35.2644,54.7356,30.0000,45.0000,0,-45.0000,30.0000,-54.7356,-54.7356,-54.7356,-35.2644,NaN,90 275,180];
sdv = abs(sind(ma));
cls = 1.5*ones(size(sdv)); % Classification Vector
cls((sdv >= 0.69) & (sdv <= 0.72)) = 0.5;
cls(sdv > 0.9) = 1;
cls(sdv < 0.1) = 0;
To see the result:
Out = [ma; cls] % Result & Matching Inputs
Experiment to get the result you want.
  2 件のコメント
Mahmoud Sami
Mahmoud Sami 2019 年 4 月 6 日
It is work very good. Thanks for your help.
Star Strider
Star Strider 2019 年 4 月 6 日
As always, my pleasure.

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

その他の回答 (1 件)

dpb
dpb 2019 年 4 月 6 日
N=1.5*ones(size(ma));
N(abs(ma)==45 | abs(ma)==135)=-0.5;
...
The rest should be self-evident from the above; lett as "exercise for student" :)
Read sections on 'logical indexing' for how and why the above works but it is a most powerful Matlab coding idiom/syntax.
  2 件のコメント
Mahmoud Sami
Mahmoud Sami 2019 年 4 月 6 日
That's not working as i was thought.
The problem is that the result can't be as written in code.
I think there is something wrong
dpb
dpb 2019 年 4 月 6 日
Works just fine here...
>> N=1.5*ones(size(ma))
N =
1.5000 1.5000 1.5000 1.5000 1.5000 1.5000 1.5000 1.5000 1.5000 1.5000 1.5000 1.5000 1.5000 1.5000 1.5000 1.5000 1.5000
>> N(abs(ma)==45 | abs(ma)==135)=-0.5
N =
1.5000 1.5000 1.5000 -0.5000 -0.5000 1.5000 1.5000 1.5000 1.5000 -0.5000 1.5000 -0.5000 1.5000 1.5000 1.5000 1.5000 1.5000
>> [ma;N]
ans =
-35.2644 0 0 -45.0000 -45.0000 0 35.2644 54.7356 30.0000 45.0000 0 -45.0000 30.0000 -54.7356 -54.7356 -54.7356 -35.2644
1.5000 1.5000 1.5000 -0.5000 -0.5000 1.5000 1.5000 1.5000 1.5000 -0.5000 1.5000 -0.5000 1.5000 1.5000 1.5000 1.5000 1.5000
>>
from which can see the substitution of -0.5 for the 45-deg positions...same will work for the other values as well...
Post your code and error messages...

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

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by