首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Matlab中使用坐标系

在Matlab中使用坐标系
EN

Stack Overflow用户
提问于 2011-10-18 22:20:19
回答 2查看 4.3K关注 0票数 0

我一直在做一个项目,涉及到电磁波场中已知的逆源问题。我的问题是,我必须在2D空间中定义3个点。当然,这些点应该有一个x,y坐标和一个定义其当前状态的值。如下所示:

代码语言:javascript
复制
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空间,并按照我所描述的方式来做。感谢大家的帮助!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-10-18 23:04:49

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

代码语言:javascript
复制
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

你必须定义一个足够大的网格来满足你的需求。

票数 0
EN

Stack Overflow用户

发布于 2011-10-27 16:16:04

下面是一个完整的示例,可能会对您有所帮助:

代码语言:javascript
复制
%# 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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7808777

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档