How to average multiple cells into new cell?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
reyadh Albarakat
el 2 de Dic. de 2016
Respondida: Guillaume
el 2 de Dic. de 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
0 comentarios
Respuesta aceptada
Guillaume
el 2 de Dic. de 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;
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!