All my points are not showing up after for-loop
Afficher commentaires plus anciens
I have three matrixes. One with x values, one for y values and a last for mass. Where the mass in point (1,1) is located in the location given by x(1,1) and y(1,1).
I am trying to create a new matrix showing the mass combined in a map grid.
[xi,yi] = meshgrid(300:0.25:380,0:0.25:90);
B = zeros(size(yi,1),size(xi,2));
for i = 1: size(xi,2)
for j = 1: length(yi)
m = find((x<(xi(1,i)+0.1250)) & (x>(xi(1,i))-0.1250));
n = find((y<(yi(j,1))+0.1250) & (y>(yi(j,1))-0.1250));
if length(m)<=length(n)
for k = 1:length(m)
if m(k) == n(k)
B(j,i) = B(j,i) + bmass(m(k));
end
end
end
if length(m) > length(n)
for k = 1: length(n)
if n(k) == m(k)
B(j,i) = B(j,i) + bmass(n(k));
end
end
end
end
end
when finished my new matrix B only contains 170 points which are non-zero. I know that in my bmass variable has over 60'000 values, and all should be located in the region of interest.
Thanks for any advice to how to improve code (new to matlab, so any comments on how to improve is welcome)
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!