Effacer les filtres
Effacer les filtres

How to average multiple cells into new cell?

4 vues (au cours des 30 derniers jours)
reyadh Albarakat
reyadh Albarakat le 2 Déc 2016
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

Réponse acceptée

Guillaume
Guillaume le 2 Déc 2016
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;

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by