matlab - store index of matrix for minimum -


i have 2d matrix ac(yr,j).
want compare each value of 1d array , store value of array absolute minimum coming.

for yr=1:32,      j=1:12,          in=1.5:1:32.5,               actin=ac(yr,j);               kar(in-0.5)=abs(in-actin);               dab(yr,j)=min(kar(kar>=0));                      end             end   end   

i'm able find least positive value not value of in coming.

you need call max shown below in order index instead of value.

[~, dab(yr,j)] = min(kar(kar>=0)); 


in order rid of nested loops try arrayfun. define operation performed on every array element.

function [index] = myminfunction(value, data)     [val, index] = min(abs(data - value)); end 

execute defined operations.

dab = arrayfun(@(x)myminfunction(x, in), ac) 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -