how to find index in matrix and average data ?

8 ビュー (過去 30 日間)
Lilya
Lilya 2022 年 5 月 24 日
コメント済み: Lilya 2022 年 5 月 25 日
Hi,
I am working on a matrix with a dimension of (72,45,1090) which I want to find all the data is >= 15.
I used the following lines to extract the indices but want to return the indices back to have a 3d matrix, not a vector array.
Once this happened, I calculated a weekly average of the third dimension (1090), but it returned an error.
Any help will be appreciated.
% extract data greater than 15 degree
ng=find(sst>=15);
sz = size(sst);
[row, col, page] = ind2sub(sz,ng);
l = sst(sub2ind(sz,row,col,page));
% calculte weekly average
wsst = reshape(sst,sz(1),sz(2),[],7);
out = nanmean(wsst,4)

採用された回答

Constantino Carlos Reyes-Aldasoro
Constantino Carlos Reyes-Aldasoro 2022 年 5 月 24 日
You can try the following, instead of "finding" the locations, which will be the indices, just use the locations like this:
sst = rand(10,20,30)*20;
ng=(sst>=15);
valuesAbove15 =sst(ng);
that would find all the values that are above 15. Notice that I simulated sst with random values of size [10 20 30].
if you then use the find:
ng2=find(sst>=15);
[row, col, page] = ind2sub(sz,ng2);
That would generate vectors of the locations of the same size as valuesAbove15, so you can now combine like this
mean(valuesAbove15(page==30))
and that would calculate the average values of the values above 15, that are in page==30. Just change to your values of interest and that would solve your problem hopefully.
  1 件のコメント
Lilya
Lilya 2022 年 5 月 25 日
Thanks very very much!!

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by