フィルターのクリア

I do have a matrix A(n,n) and a matrix B(m,n) m<n and want to create a third matrix C(n,n) where C(i,j)= k if A(i,j)<=B(k,j) && if A(i,j)>B(k-1,j).

2 ビュー (過去 30 日間)
The question is to rank the element of each vector (column) in A(n,n) according to the order in B(m,n) and get a new matrix with these ranks. It is a classification of elements by column : example:
A = [0 4 7 ;
1 3 5 ;
3 3 6 ]
B = [0 0 1 ;
3 1 2 ]
A(1,1)<=B(1,1)==>C(1,1)=1<---the index of zero in B;
A(2,1)>B(1,1)=0 && A(2,1)<=B(2,1) ==> C(2,1)=2
A(3,1)==B(2,1)> B(1,1)=0 ==> C(3,1)=2 and go next to the second column, then next one to get
C=[1 2 2, C(:,2),C(:,3)]
  1 件のコメント
Image Analyst
Image Analyst 2017 年 4 月 13 日
I don't understand the rule(s). Why does A(1,1) get compared to B(1,1) but the second element of the first column of A get compared to two elements of B, and the third element of the first column of A gets compared to B(2,1) but then B(2,1) gets compared to B(1,1)? Why do you need to do this complicated thing?

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

採用された回答

Santhana Raj
Santhana Raj 2017 年 4 月 13 日
You can create three nested loops for i, j and k. and check for your condition:
if ((A(i,j)<=B(k,j) && (A(i,j)>B(k-1,j))
Take care that, when k=1, you cant check both the conditions and only the first conditions is to be applied.
Hope it helps.
  1 件のコメント
Youssef
Youssef 2017 年 4 月 13 日
Thank you very much. I used a first condition to take care about the first row. I used the same code in 2015b version, and it gave me an error "Subscript indices must either be real positive integers or logicals.". But I run it in an old version (20114b) and it works!!!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Statistics and Machine Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by