I have a matrix A = [ 1 2 3; 3 5 9; 1 8 0; 2 3 3 ] and the value of third row is stored in another matrix B = [1 8 0], how can i subtract B from A? i tried this A(B,:)=[] but not working.

 Accepted Answer

Stephen23
Stephen23 on 21 May 2017
Edited: Stephen23 on 21 May 2017
>> A = [1,2,3;3,5,9;1,8,0;2,3,3];
>> B = [1,8,0];
>> [~,idx] = ismember(B,A,'rows');
>> A(idx,:) = []
A =
1 2 3
3 5 9
2 3 3

2 Comments

Thanks @Stephen, can you please tell me what does this line means?
[~,idx] = ismember(B,A,'rows');
Stephen23
Stephen23 on 21 May 2017
Edited: Stephen23 on 21 May 2017
Everything you need to know about that line is explained clearly in the documentation for ismember, so there is no point in me simply repeating it here. I am sure that you are capable of finding and reading the documentation yourself.

Sign in to comment.

More Answers (0)

Tags

Asked:

on 21 May 2017

Edited:

on 21 May 2017

Community Treasure Hunt

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

Start Hunting!