how to find index in matrix and average data ?
조회 수: 7 (최근 30일)
이전 댓글 표시
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)
댓글 수: 0
채택된 답변
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!