Finding out if the max value in a vector is in a certain interval in a vector?

So im in need of a if statement that looks something like this:
%if max(C) == C(1,16)
% iMax = 1;
%elseif max(C) == C(17,32)
% iMax = 2;
%elseif max(C) == C(33,48)
% iMax = 3;
%elseif max(C) == C(49,64)
% iMax = 4;
%end
and I want to check if the max value in the (1,64)vector C lies in the interval of (1,16), (17,32), (33,48) or (49,64)
but this is probably not the way to do it.
need some help, thanks in advance!

 Accepted Answer

[~,idx]=max(C); % location of max in C
imax=fix((idx-1)/16)+1; % compute the subsection

4 Comments

These are the times it would be nice to have a Matlab syntax that allowed one to ignore the default argument from a function in an expression. Like, say,
imax=fix(([~,max(C)]-1)/16)+1;
to avoid the need for the temporary index variable.
Im working on a 2048 project, and I have a heuristic variance function with two other heuristic functions that counts the negative sum over the matrix and one that counts the tiles with zeros as positive, and the board is logarithmed, but I dont really understand if its good to have negative variance or positive? and is this:
function v = Variance(B)
v = -var(B(:));
end
the best way to calculate the variance across a matrix? thanks @dpb
I have no idea what any of that said...and never heard of a negative variance. But, the colon notation to reference all elements of an array >1D is the "trick" for such computations, yes...

Sign in to comment.

More Answers (0)

Categories

Find more on Language Fundamentals in Help Center and File Exchange

Asked:

on 3 Dec 2015

Commented:

dpb
on 4 Dec 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!