Question

Suppose there is a matrix generated using for loop which is given as

A = [ 1 3 4 ;...
      5 8 9 ;...
      6 3 8 ]

Let another matrix be generated from a given A matrix as

B = [ 5 3 8 ]

My question is: I want to generate a matrix by removing only elements of B from A column wise only.

output

C = [ 1 8 4 ;... 
      6 3 9 ]

How to do this using Matlab?

Était-ce utile?

La solution

This should work assuming that the number of elements removed from each row is the same.

A = [1 3 4; 5 8 9; 6 3 8];
B = [3 5 8];

C = A';
C(find(A' == repmat(B, size(A, 2), 1))) = [];
C = reshape(C, [], size(A, 1))'
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top