Matlab:将阈值应用于矩阵中的一维

Gjo*_*gji 3 matlab

我有一个矩阵M(x,y).我想在x中的所有值中应用阈值,如果x

例:

M = 1,2; 3,4; 5,6;

如果在第一维上应用t = 5,则结果为

R = 0,2; 0,4; 5,6;

mat*_*fee 5

一种方法(用于M(:,1)选择第一列; M(:,1)<5返回第一列中至少为5的项的行索引) -

> R = M;
> R(M(:,1)<5,1) = 0

R =

   0   2
   0   4
   5   6
Run Code Online (Sandbox Code Playgroud)

另一个 -

R = M;
[i,j]=find(M(:,1)<5); % locate rows (i) and cols (j) where M(:,1) < 5
                      % so j is just going to be all 1
                      % and i has corresponding rows
R(i,1)=0;
Run Code Online (Sandbox Code Playgroud)