If I have two 2-D datasets with identical dimension sizes, how can I filter data from one at certain gridpoints where the other dataset meets a certain condition?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Joseph Miscimarra
el 6 de Ag. de 2019
Comentada: Joseph Miscimarra
el 8 de Ag. de 2019
I'm dealing with NetCDF data which I read into a MATLAB array. They are both 141x301 double matrices. One of them has a numeric indicator for certain objects; think of it as a map that has contiguous shapes, and each shape has a unique identifier that is between 1 and 100, with all blank spaces as 0. Additionally, there can be multiple shapes on the same map. The OTHER matrix contains values for each grid point, and I want to find the max value for each distinct shape.
Is there a way to find the max for each shape without using a double for-loop? I will do that if I have to but I want to avoid that because I'm already doing this over many arrays and I don't want to end up with tons of nested for-loops.
0 comentarios
Respuesta aceptada
KSSV
el 7 de Ag. de 2019
A = randi([1 5],5,5) ; % shapes
B = rand(5) ; % data
[c,ia,ib]= unique(A) ;
N = length(c) ;
% GEt max values
iwant = zeros(N,1) ;
for i = 1:N
iwant(i) = max(B(ib==i)) ;
end
Más respuestas (0)
Ver también
Categorías
Más información sobre NetCDF 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!