声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1348|回复: 11

[绘图技巧] 坐标显示中的数据格式的转换问题

[复制链接]
发表于 2008-2-28 16:30 | 显示全部楼层 |阅读模式

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

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

x
clear all
TT=[200601 200603 200605 200607];
Final_b=[0.27 0.37 0.35 0.46];
plot(TT',Final_b','-.b.');
set(gca,'xtick',TT);
set(gca,'xticklabel',TT);
datacursormode on;

这个程序生成的图中,鼠标点所取得的坐标值显示的是科学记数法.怎样改为正常的?
比如x:2.006e+005 y:0.3982, 将x显示为200605这样的格式.应该怎样修改?

[ 本帖最后由 eight 于 2008-2-28 17:06 编辑 ]
回复
分享到:

使用道具 举报

发表于 2008-2-28 19:57 | 显示全部楼层
修改updatefcn函数

function Untitled
clear all
TT=[200601 200603 200605 200607];
Final_b=[0.27 0.37 0.35 0.46];
plot(TT',Final_b','-.b.');
set(gca,'xtick',TT);
set(gca,'xticklabel',TT);
dcm_obj = datacursormode(gcf);
set(dcm_obj,'UpdateFcn',@myfunction);
datacursormode on;

function output_txt = myfunction(obj,event_obj)
% Display the position of the data cursor
% obj          Currently not used (empty)
% event_obj    Handle to event object
% output_txt   Data cursor text string (string or cell array of strings).

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

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

评分

2

查看全部评分

 楼主| 发表于 2008-2-29 10:08 | 显示全部楼层
谢谢楼上的。不过运行了一下,为何框框里显示的是:Error in custom datatip string function?
发表于 2008-2-29 10:16 | 显示全部楼层


已测试,没有问题。你用哪个版本的 matlab
 楼主| 发表于 2008-2-29 10:18 | 显示全部楼层
matlabR2007a
发表于 2008-2-29 10:20 | 显示全部楼层
原帖由 zdltwo 于 2008-2-29 10:18 发表
matlabR2007a


me 2 . 你是copy到m文件中然后运行的吗?

[ 本帖最后由 eight 于 2008-2-29 10:24 编辑 ]
 楼主| 发表于 2008-2-29 10:27 | 显示全部楼层
是的阿。直接copy运行,结果这样
??? function Untitled
    |
Error: Function definitions are not permitted at the prompt or in scripts.
我把function output_txt = myfunction(obj,event_obj)后面的部分拷到另一个edit里,就出现最先那个问题。
发表于 2008-2-29 10:29 | 显示全部楼层
原帖由 zdltwo 于 2008-2-29 10:27 发表
是的阿。直接copy运行,结果这样
??? function Untitled
    |
Error: Function definitions are not permitted at the prompt or in scripts.
我把function output_txt = myfunction(obj,event_obj)后面的部分拷 ...


不能 copy 到命令窗口,你把 yangzj 所贴的所有代码都 copy 到编辑窗口中,然后保存、运行便可
 楼主| 发表于 2008-2-29 10:38 | 显示全部楼层
对,我是拷贝到edit窗口的阿
 楼主| 发表于 2008-2-29 10:42 | 显示全部楼层
可以了。
刚才拷贝过去没有保存,只是选中之后右键Evaluate Selection。
保存之后就可以了。
谢谢。
 楼主| 发表于 2008-2-29 10:43 | 显示全部楼层
为什么一定要保存了才可以?
发表于 2008-2-29 10:45 | 显示全部楼层
原帖由 zdltwo 于 2008-2-29 10:38 发表
对,我是拷贝到edit窗口的阿

Function definitions are not permitted at the prompt or in scripts
这个错误就是copy到命令窗口才会出现的。

按照以下步骤做:
1. 菜单File-->New-->M-File
2. copy 2楼的所有代码
3. 粘贴到第1部新建的 mfile 中
4. 保存,运行

评分

1

查看全部评分

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-9-23 15:31 , Processed in 0.064915 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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