All my points are not showing up after for-loop
显示 更早的评论
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)
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!