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!

 採用された回答

dpb
dpb 2015 年 12 月 3 日
[~,idx]=max(C); % location of max in C
imax=fix((idx-1)/16)+1; % compute the subsection

4 件のコメント

Patrick Karlsson
Patrick Karlsson 2015 年 12 月 3 日
Thanks, this helped alot!
dpb
dpb 2015 年 12 月 3 日
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.
Patrick Karlsson
Patrick Karlsson 2015 年 12 月 3 日
編集済み: Patrick Karlsson 2015 年 12 月 3 日
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
dpb
dpb 2015 年 12 月 4 日
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...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2015 年 12 月 3 日

コメント済み:

dpb
2015 年 12 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by