0

我一直在从事一个涉及电磁波领域内已知的逆源问题的项目。我的问题是;我必须在 2D 空间中定义 3 个点。这些点当然应该有 ax,y 坐标和一个定义其电流的值。像这样:

A1(2,3)=1
A2(2,-2)=2
and so on.

我还必须围绕它定义一个圆圈并将其分成 200 个点。就像第一点一样;说R=2 ; B1(2,0) ;B50(0,2);B100(-2,0)等等。

现在我真的很难在 MATLAB 中定义一个空间并圈出它。所以我要问的是帮助我定义一个 2D 空间并按照我描述的方式去做。感谢您的帮助!

4

2 回答 2

0

这是一个可能有帮助的完整示例:

%# points
num = 3;
P = [2 3; 2 -2; -1 1];          %# 2D points coords
R = [2.5 3 3];                  %# radii of circles around points

%# compute circle points
theta = linspace(0,2*pi,20)';   %'
unitCircle = [cos(theta) sin(theta)];
C = zeros(numel(theta),2,num);
for i=1:num
    C(:,:,i) = bsxfun(@plus, R(i).*unitCircle, P(i,:));
end

%# prepare plot
xlims = [-6 6]; ylims = [-6 6];
line([xlims nan 0 0],[0 0 nan ylims], ...
    'LineWidth',2, 'Color',[.2 .2 .2])
axis square, grid on
set(gca, 'XLim',xlims, 'YLim',ylims, ...
    'XTick',xlims(1):xlims(2), 'YTick',xlims(1):xlims(2))
title('Cartesian Coordinate System')
xlabel('x-coords'), ylabel('y-coords')

hold on

%# plot centers
plot(P(:,1), P(:,2), ...
    'LineStyle','none', 'Marker','o', 'Color','m')
str = num2str((1:num)','A%d');    %'
text(P(:,1), P(:,2), , str, ...
    'HorizontalAlignment','left', 'VerticalAlignment','bottom')

%# plot circles
clr = lines(num);
h = zeros(num,1);
for i=1:num
    h(i) = plot(C(:,1,i), C(:,2,i), ...
        'LineStyle','-', 'Marker','.', 'Color',clr(i,:));
end
str = num2str((1:num)','Circle %d');    %'
legend(h, str, 'Location','SW')

hold off

截屏

于 2011-10-27T08:16:03.560 回答
0

可以使用这种代码。grid在变量编辑器中查看。

grid = zeros(50, 50);
R = 10;
angles = (1:200)/2/pi;
x = cos(angles)*R;
y = sin(angles)*R;

center = [25 20];

for n=1:length(angles)   
    grid(center(1)+1+round(x(n)), center(2)+1+round(y(n))) = 1;
end

您必须定义一个足够大的网格以满足您的需要。

于 2011-10-18T15:04:49.387 回答