Threshold the matrix with vector

1 回表示 (過去 30 日間)
Aravin
Aravin 2012 年 10 月 8 日
Let say I have a matrix M with m x n dimensions. I want to threshold each column by different threshold. let say N contains the threshold for each column, therefore the dimension of N is n x 1 or 1 x n.
how can I do this by single command.

採用された回答

Junaid
Junaid 2012 年 10 月 8 日
One possible way is ..
lets us assume that N is 1 x n vector
N = repmat(N,size(M,1),1);
M_binary = M > N;
or
M_binary = M < N;

その他の回答 (1 件)

Wayne King
Wayne King 2012 年 10 月 8 日
編集済み: Wayne King 2012 年 10 月 8 日
A = randn(5,3);
n = [0.5 0.8 0.2];
thresh = bsxfun(@gt,A,n);
B = A.*thresh;
B contains nonzero elements only where elements in A exceed the thresholds in the vector n.
  2 件のコメント
Aravin
Aravin 2012 年 10 月 8 日
Thanks Wayne, but it is not giving me 0 1 matrix as after thresholding B should be binary ???
Wayne King
Wayne King 2012 年 10 月 8 日
thresh is the 0 1 matrix just as I describe above

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by