how to delete particular row in given matrix ?

like this matrix
a=[190.6412 159.7899 0.9991];
b=[180.1084 166.6349 0.9992
190.6412 159.7899 0.9991
179.5966 155.4710 1.0000
196.5314 166.2689 1.0000];
than the answer should be like this
c= [180.1084 166.6349 0.9992
179.5966 155.4710 1.0000
196.5314 166.2689 1.0000];
i should delete only 'a' matrix from the 'b' matrix and display as 'c' matrix

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 4 Nov. 2014
Bearbeitet: Azzi Abdelmalek am 4 Nov. 2014

0 Stimmen

c=setdiff(b,a,'rows')

10 Kommentare

Matlab111
Matlab111 am 4 Nov. 2014
Bearbeitet: Matlab111 am 4 Nov. 2014
it's showing Error "a and b must have the same number of columns." in my case 'a' matrix will be same but 'b' matrix will get varies.
Adam
Adam am 4 Nov. 2014
You should give an example that matches your edge case scenarios then as what you say doesn't seem to make sense.
If a and b have different number of columns then clearly none of the rows of b will be equal to a as you cannot delete just part of a row from a numeric matrix
Matlab111
Matlab111 am 4 Nov. 2014
Bearbeitet: Matlab111 am 4 Nov. 2014
her example:
a=[190.6412 159.7899 0.9991];
b=[180.1084 166.6349 0.9992
190.6412 159.7899 0.9991
179.5966 155.4710 1.0000
196.5314 166.2689 1.0000];
here 'a'matrix size will be constant (1x3), but 'b' matrix will get different,it depends on for loop, 'b' will be like 'nx3 matrix'.
Adam
Adam am 4 Nov. 2014
Azzi's answer works fine in that case. If it is just number of rows that changes that is fine. Only if number of columns changes do you have a problem which is what your error message suggested is your case.
Matlab111
Matlab111 am 4 Nov. 2014
it's showing Error like "a and b must have the same number of columns."
Adam
Adam am 4 Nov. 2014
That is odd because they do have the same number of columns and it works fine for me.
Can you please either show the a and b you have when that error occurs, or do
whos a b
and report the result. As Adam said, if a is 1-by-3 and b is n-by-3, then Azzi's solution should work. If b is n-by-[anything other than 3], then you'd see the error you're seeing.
If b should always have 3 columns, then you most likely have something else causing a problem. If b can have a different number of columns, then you need to explain what behavior you'd like to see.
Matlab111
Matlab111 am 4 Nov. 2014
Bearbeitet: Matlab111 am 4 Nov. 2014
sorry, guys now i'm getting thanks for u r support.
And this works just fine :
a=[190.6412 159.7899 0.9991];
b=[180.1084 166.6349 0.9992
190.6412 159.7899 0.9991
150.6412 169.7899 0.9995
179.5966 155.4710 1.0000
196.5314 166.2689 1.0000];
c=setdiff(b,a,'rows')
No error whatsoever. Please post the ACTUAL REAL code you are using, not this code that you just did, which works perfectly fine.
Matt Tearle
Matt Tearle am 4 Nov. 2014
You seem to be saying that the number of columns of b will vary, but above you also said that 'b' will be like 'nx3 matrix', which means that b will always have 3 columns. And the example you keep showing has 3 columns.
So, again, you need to tell us what behavior you expect for b: should b always have 3 columns, or can the number of columns of b change?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

the cyclist
the cyclist am 4 Nov. 2014

0 Stimmen

Here's one way:
tf = ismember(b,a,'rows')
c = b(not(tf),:)

1 Kommentar

Matlab111
Matlab111 am 4 Nov. 2014
Bearbeitet: Matlab111 am 4 Nov. 2014
it's showing Error "A and S must have the same number of columns." in my case 'a' matrix will be same but 'b'matrix will get varies.

Melden Sie sich an, um zu kommentieren.

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by