How to average multiple cells into new cell?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi all,
I have 39 cells each one has matrix (317*202). I want to get the average of all cells in new cell with same dimension (317*202). Thank you in advance
Here is the code
cd F:\NDWI_INDEXes\VNDWI\MOD09A1_HU\VNDWI_HU_2000;
F_read=dir('*.tif');
for i=1:length(F_read)
vndwi_HU{i}= F_read(i).name;
vndwi_HU{i} = imread(vndwi_HU{i});
vndwi_HU{i}(vndwi_HU{i}>1)=NaN;
vndwi_HU{i}(vndwi_HU{i}<0)=NaN;
vndwi_HU{i}(vndwi_HU{i}==0)=NaN;
end
댓글 수: 0
채택된 답변
Guillaume
2016년 12월 2일
You would be much better off using a 3D matrix (of size 317*202*numel(F_read)) instead of a cell array for storage. This is also the way to getting what you want:
vndwi_HUmat = cat(3, vndwi_HUmat{:}); %convert cell array into 3D matrix
vndwi_mean = mean(vndwi_HUmat, 3); %and get the average across 3rd dimension == across cells
Your thresholding operation would have been easier that way. After the loop you just had to do:
vndwi_MUmat(vndwi_MUmat > 1 | vndwi_MUmat <= 0) = NaN;
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!