How to delete a row if it is smaller than other rows with specific rule?
Ältere Kommentare anzeigen
we say vector a <= b iff a(i)<=b(i) for i=1:size(a).
Now I need to compare rows of a matrix with that rule and delete the biggest row. of course, some rows are incomparable and I need to keep them as well. How can I do this in Matlab? For example for this Matrix
A=[59 98 30 171;
38 56 10 100;
72 100 29 149;
56 96 23 157;
58 97 22 260];
I would be very thankful if you help me. thank you.
11 Kommentare
Image Analyst
am 29 Jul. 2018
Bearbeitet: Image Analyst
am 29 Jul. 2018
Please give your expected results for vectors little "a" and little "b".
And say how big 2-D matrix "A" is related to your condition involving 1-D vectors "a" and "b" on the first line.
And what exactly makes incomparable rows of 2-D matrix "A"? What would prevent you from comparing the two rows by subtracting them? It seems like every row should be able to be compared to any other row by subtraction.
Ali Moghanni
am 29 Jul. 2018
Ali Moghanni
am 29 Jul. 2018
Image Analyst
am 29 Jul. 2018
Bearbeitet: Image Analyst
am 29 Jul. 2018
What if row 8 has all elements bigger than row 7 but not all bigger than row 9? Exactly which rows get compared? All against all? Just the above one vs. the one immediately below it? or above it?
Again, please give your expected output.
Ali Moghanni
am 29 Jul. 2018
Bearbeitet: Ali Moghanni
am 29 Jul. 2018
Image Analyst
am 29 Jul. 2018
Again what does not comparable mean to you?
Any rows can be compared - you just subtract them. What could prevent you from subtracting (comparing) them? After the subtraction, you use the all() function.
Have you seen the all() function?
Ali Moghanni
am 29 Jul. 2018
Image Analyst
am 29 Jul. 2018
Watch while I compare those two rows:
comparison = [12 45 35 122] - [15 40 35 120]
There. They have been compared, if subtraction is what you mean by comparison.
Look again in the help for all(). It's been there forever.
Ali Moghanni
am 29 Jul. 2018
Image Analyst
am 29 Jul. 2018
So all rows CAN be compared, like I said, and the comparison will be either true or false depending on whether all elements of row 1 are less than or equal to all elements of row 2, just like I did in my code below. Anything wrong with that code?
Ali Moghanni
am 29 Jul. 2018
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Programming finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!