필터 지우기
필터 지우기

how to find index in matrix and average data ?

조회 수: 5 (최근 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
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by