I'm fairly new to programming in general and MATLAB and I'm having some problems with removing values from matrix.
I have matrix tmp2 with values:
tmp2 = [... ...
0.6000 20.4000
0.7000 20.4000
0.8000 20.4000
0.9000 20.4000
1.0000 20.4000
1.0000 19.1000
1.1000 19.1000
1.2000 19.1000
1.3000 19.1000
1.4000 19.1000
... ...];
How to remove the part where on the left column there is 1.0 but the values on the right one are different? I want to save the row with 19.1. I searched for solutions but found some that delete both rows using histc function and that's not what i need.
Thanks
You can do this using
unique
:By default,
unique
saves the last unique value it finds, and the output will be sorted. This happens to be what you want/have, so you're in luck :)If this is not what you want/have, you'll have to tinker a bit more. Removing duplicates preserving the order goes like this:
which still preserves the last entry found. If you want to keep the first entry found, use
I saw the solution with unique, and wanted to give a solution with loops. You can take a look to see which one is faster :D! The loop could probably be ameliorated...
use
unique
without'rows'
option