Maintain shape of logical index mask

4 次查看(过去 30 天)
I have a matrix A=[1,2,3;4,5,6]. From this, I want to remove (by row), z=[1,5], to return the matrix B=[2,3;4,6]. I'm trying to use logical indexing to do this, but that returns a vector instead of the matrix B.
if true
B=A(A~=z(:,1))
end

采纳的回答

Andrei Bobrov
Andrei Bobrov 2017-6-12
编辑:Andrei Bobrov 2017-6-12
Aout = A';
Aout = reshape(Aout(Aout ~= z(:)'),[],2)';
or
Aout = A';
Aout = reshape(Aout(~ismember(Aout,z)),[],2)';

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by