我试图在Matlab中编写代码来计算影响类型问题的区域。这是我的数据(加权,x-coord,y-coord)的作用:
M =
15072.00 486.00 -292
13269.00 486.00 -292
12843.00 414.00 -267
10969.00 496.00 -287
9907.00 411.00 -274
9718.00 440.00 -265
9233.00 446.00 -253
9138.00 462.00 -275
8830.00 496.00 -257
8632.00 432.00 -253
R =
-13891.00 452.00 -398
-13471.00 461.00 -356
-12035.00 492.00 -329
-11309.00 413.00 -353
-11079.00 467.00 -375
-10659.00 493.00 -333
-10643.00 495.00 -338
-10121.00 455.00 -346
-9795.00 456.00 -367
-8927.00 485.00 -361
-8765.00 467.00 -351
我想根据每个坐标的30的影响圆来计算任意给定位置的权重总和。
我曾考虑使用for循环独立计算每个点并对结果求和,但似乎不必要的复杂和低效。
我还想过为每个圆圈分配颜色强度并覆盖它们但是我不知道如何根据值改变颜色强度这是我到目前为止的尝试(我希望看到结果):< / p>
function [] = Influence()
M = xlsread('MR.xlsx','A4:C310');
R = xlsread('MR.xlsx','E4:G368');
%these are my values around 300 coordinates
%M are negative values and R positive, I want to see which are dominant in their regions
hold on
scatter(M(:,2),M(:,3),3000,'b','filled')
scatter(R(:,2),R(:,3),3000,'y','filled')
axis([350 650 -450 -200])
hold off
end
%had to use a scalar of 3000 for some reason as it isnt correlated to the graph size
感谢您的任何想法/解决方案
答案 0 :(得分:0)
这个怎么样:
r_influence = 30; % radius of influence
r = @(p,A) sqrt((p(1)-A(:,2)).^2 + (p(2)-A(:,3)).^2); % distance
wsum = @(p,A) sum(A(find(r(p,A)<=r_influence),1)); % sum where distance less than roi
% compute sum on a grid
xrange = linspace(350,550,201);
yrange = linspace(-200,-450,201);
[XY,YX] = meshgrid(xrange,yrange);
map_M = arrayfun(@(p1,p2) wsum([p1,p2],M),XY,YX);
map_R = arrayfun(@(p1,p2) wsum([p1,p2],R),XY,YX);
figure(1);
clf;
imagesc(xrange,yrange,map_M + map_R);
colorbar;
给出这样的图片:
这就是你要找的东西吗?