Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab - Select Specific Row Based on Condition

points = [  
    -9.9043877608991468201413092380493, 426.34796945271797204125533010993, Maximum  
    -2.9714737944057521874892206269196, 422.13223302035451265143272598599, Minimum
    9.3758615553048990076305298649689, 441.87005169359418197397861057075, Maximum
]

I'd like to do loop through and create a new matrix with just the values where column three matches 'Maximum'.

When trying:

idx = ( points(:,3)=='Maximum' )

I get:

Maximum == Maximum
Minimum == Maximum
Maximum == Maximum

Any ideas? Thanks!

like image 742
Kevin Murphy Avatar asked Oct 13 '12 02:10

Kevin Murphy


1 Answers

the matrix points as is presented is not a valid matlab matrix unless Maximum is a number. If that is the case then:

  idx=find( points(:,3)== Maximum  )

will give you the proper indices.

Edit

to obtain a new matrix with the values of "maximum" just

 new_matrix=points(idx,1:end-1)
like image 191
bla Avatar answered Oct 27 '22 07:10

bla