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!