matlab - Find an index position within a matrix -


in example have matrix (a)

a = 1       2       3       7     0.9     0.6     0.2    0.2     0.8     17      72     15 

my goal search through matrix , find index position of highest value not >= 72. matrix illustration know how matrix of dimension rows , columns equal (2x2 3x3 4x4 ...)

in case calculate fact highest number within constraints

rows=3 cols = 2

thanks

step 1: determine value you're interested in.

val = max(a(a<72)); 

step 2: find index of element corresponds value:

[r,c] = find(a==val,1,'first'); #%only take first element (this can changed) #r row index, c column index 

you use linear indexing , ind2sub:

l = find(a==val); #%this time, find elements meet criteria [r,c] = ind2sub(size(a),l); 

here links documentation find , ind2sub. don't have store value (val) of interest either, can put in 1 line.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -