Odd output from ind2sub

2 ビュー (過去 30 日間)
Kate
Kate 2014 年 7 月 23 日
コメント済み: Kate 2014 年 7 月 23 日
I'm trying to spit out indices for max values in a large matrix at a specific point in time (in this case obs 1560, t(:, :, 1560))
>> [I J]=ind2sub(size(t), (max(max(t(:, :, 1560)))))
But my I is equal to the actual value in the cell, not the row
I =
28.5048
And J makes no sense:
J =
1
Is the error in my code obvious to anyone? Thanks,

採用された回答

Andrei Bobrov
Andrei Bobrov 2014 年 7 月 23 日
編集済み: Andrei Bobrov 2014 年 7 月 23 日
s = size(t);
[val,ij] = max(reshape(t(:, :, 1560),[],1);
[ii,jj] = ind2sub(s(1:2),ij);
idxs = [ii,jj,1560];
or
ind = prod(s(1:2))*1559 + ij;
  1 件のコメント
Kate
Kate 2014 年 7 月 23 日
Thanks Andrei, reshape was the addition that I needed.

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

その他の回答 (1 件)

dpb
dpb 2014 年 7 月 23 日
(max(max(t(:, :, 1560))))
is a single value for the maximum of the values of the requested plane. Thus there isn't any actual location to be converted from being returned.
If you write
[i,j]=ind2sub(size(t), find(max(max(t(:, :, 1560)))))
instead, you'll always get [1,1] because the result of the double max() operation is scalar.

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by