matlab - Use logical indexing instead of FIND -


within loop in code use one-liner find , plot minimum of potential (for clarity: 7 corresponds cells containing potential values, 5 x-values):

plot(pddata{subject,5}{1,1}(find(pddata{subject,7}==...     min(pddata{subject,7}))),min(pddata{subject,7}),'ko') 

now matlab suggests use logical indexing instead of find , although i've looked briefly, doesn't strike me should here. main question here whether should employ logical indexing (i prefer keep one-liner!), , if so: how?

i apologize in advance asking such minor question, i'm trying increase matlab knowledge short answer me out already!

dennis correct in comment. idea using logical indexing directly cuts out step. if you're trying extract elements in matrix greater 2 example, using find this:

a = [1 3 2 1 4 1] a(find(a>2)) 

which becomes like

a(find([0 1 0 0 1 0])) 

then

a([2, 5]) 

and finally

[3, 4] 

however if used logical indexing directly this:

a(a>2) 

you get

a([0 0 1 0 0 1 0]) 

and finally

[3,4] 

so same result, , skip call find can see extraneous in these cases.

then add pretty cool, unless matlab pretty old, mlint (the bit gives warning) can fix you. if hover on find underlined in red this:

enter image description here

so basic version of mistake, see @ end there little fix button. after clicking it:

enter image description here

ok in instance it's normal indexing instead of logical point remains, mlint can fix pretty awesome!


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -