声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1663|回复: 8

[绘图技巧] matlab在用polar画图

[复制链接]
发表于 2014-4-19 12:53 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
matlab在用polar画出的极坐标图中,用Date Cursor标识显示的是直角坐标的坐标,而不是幅值和角度?为什么?急急急!!!
回复
分享到:

使用道具 举报

发表于 2014-4-19 21:10 | 显示全部楼层
不是很明白LZ的意思。给你举个例子,LZ是不是这个意思?程序代码:
  1. t = 0:.01:2*pi;
  2. polar(t,sin(2*t).*cos(2*t),'--r')
复制代码
图像如图:

楼主,可以参考这个链接:http://zhidao.baidu.com/question ... B%D7%F8%B1%EA%CD%BC
希望我的回答对你有所帮助。
1.png
发表于 2014-4-20 16:25 | 显示全部楼层
本帖最后由 牛小贱 于 2014-5-26 15:54 编辑

When data cursor mode is enabled, you can

Click on any graphics object defined by data values and display the x, y, and z (if 3-D) values of the nearest data point.data cusor显示的是直角坐标系的坐标,如果想修改显示的值,可以尝试通过修改回调函数来实现,默认回调函数:
  1. function output_txt = myfunction(obj,event_obj)
  2. % Display the position of the data cursor
  3. % obj          Currently not used (empty)
  4. % event_obj    Handle to event object
  5. % output_txt   Data cursor text string (string or cell array of strings).

  6. pos = get(event_obj,'Position');
  7. output_txt = {['X: ',num2str(pos(1),4)],...
  8.     ['Y: ',num2str(pos(2),4)]};

  9. % If there is a Z-coordinate in the position, display it as well
  10. if length(pos) > 2
  11.     output_txt{end+1} = ['Z: ',num2str(pos(3),4)];
  12. end
复制代码


点评

赞成: 3.0
赞成: 3
  发表于 2014-5-26 15:53

评分

3

查看全部评分

 楼主| 发表于 2014-5-25 12:56 | 显示全部楼层
谢谢大神的指点 ,我的意思是想显示出图像上某一点的极坐标  如(幅值,角度)
发表于 2014-5-25 16:12 | 显示全部楼层
本帖最后由 chybeyond 于 2014-5-25 16:24 编辑

极坐标系中的两个坐标 r 和 θ 可以由下面的公式转换为直角坐标系下的坐标值
x = rcos(θ),
y = rsin(θ),
由上述二公式,可得到从直角坐标系中x 和 y 两坐标如何计算出极坐标下的坐标:
r=sqrt(x^2+y^2);
θ=atan(y/x);
代码修改步骤:
在工具栏中选中datacursor图标,然后右击图形区域选择

1.jpg
将代码修改为
  1. function output_txt = myfunction(obj,event_obj)
  2. % Display the position of the data cursor
  3. % obj          Currently not used (empty)
  4. % event_obj    Handle to event object
  5. % output_txt   Data cursor text string (string or cell array of strings).
  6. pos = get(event_obj,'Position');
  7. posx = sqrt(pos(1)^2+pos(2)^2);
  8. posy = atan(pos(2)/pos(1));
  9. output_txt = {['X: ',num2str(posy,4)],...
  10.     ['Y: ',num2str(posx,4)]};
  11. %由于actan对变量要求为-pi/2~pi/2,适用第一象限制,其它象限可判断pos(1)和pos(2)的正负稍作修改即可
复制代码
保存为NewCallback.m,然后右击选择Select Text updata....打开刚才保存的NewCallback.m即可。
结果:pi/6=0.5236,r=0.5处显示为

11111111111.jpg


点评

赞成: 4.0
赞成: 4
  发表于 2014-5-26 15:54

评分

2

查看全部评分

 楼主| 发表于 2014-5-25 19:12 | 显示全部楼层
多谢大神指点  学习了
发表于 2014-5-25 19:26 | 显示全部楼层
小德 发表于 2014-5-25 19:12
多谢大神指点  学习了

不客气,互相学习
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-18 08:25 , Processed in 0.070478 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表