delete value in matrix with condition

1 回表示 (過去 30 日間)
ha ha
ha ha 2019 年 3 月 4 日
コメント済み: ha ha 2019 年 3 月 4 日
Let's say, I have 2 matrix:
A=[1 9 5 6;2 1 4 5;3 4 3 5];%matrix A
dist_A=[0.1 0.6 0.4 0.5; 0.5 0.1 0.2 0.3; 0.2 0.9 0.7 0.4];%matrix dist_A
condition=0.5;%this is value to check condition
A=[1 9 5 6
2 1 4 5
3 4 3 5];
dist_A=[0.1 0.6 0.4 0.5
0.5 0.1 0.2 0.3
0.2 0.9 0.7 0.4];
My question is:
1/ I want to delete values in matrix "dist_A" that satisfy condition: If that value <= condition(0.5)
I hope the result is:
result_dist_A=[0.1 0.4 ; 0.1 0.2 0.3; 0.2 0.4];
2/ Delete the value in matrix A having the same index of the deleted value in matrix "dist_A"
I hope the result is:
result_A=[1 5 ; 1 4 5; 3 5];
  1 件のコメント
KSSV
KSSV 2019 年 3 月 4 日
result_A=[1 5 ; 1 4 5; 3 5];
The above will trhow an error. I would suggest you to replace the unwanted value with NaN...so that dimensions remain apt and no error pops out.

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

採用された回答

madhan ravi
madhan ravi 2019 年 3 月 4 日
編集済み: madhan ravi 2019 年 3 月 4 日
R=arrayfun(@(x)A(x,dist_A(x,:)<0.5),1:size(dist_A,1),'un',0);
R{:}
Gives:
ans =
1 5
ans =
1 4 5
ans =
3 5
>>
  1 件のコメント
ha ha
ha ha 2019 年 3 月 4 日
@madhan ravi . Thanks so much.

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

その他の回答 (0 件)

カテゴリ

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