声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 4011|回复: 1

[求助]如何用set改变gca变量中xtick和ytick的属性值

[复制链接]
发表于 2006-2-24 22:32 | 显示全部楼层 |阅读模式

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

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

x
恰恰前
回复
分享到:

使用道具 举报

发表于 2006-2-25 18:58 | 显示全部楼层

回复:(qwert)[求助]如何用set改变gca变量中xtick和...

<P>How do I format tick labels? --From mathworks</P>
<P>Problem Description <BR>How do I format tick labels? </P>
<P>I have an axis with tick labels and I want them all to have 3.1 format. For example, I do a plot (1:5) and I change my tick labels using the command </P>
<P>set(gca, 'XTick', [1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0]) </P>
<P>However, they appear as: </P>
<P>[1 1.5 2 2.5 3 3.5 4 4.5 5] </P>
<P>How do I get them to appear as I typed them in the above command? </P>
<P><BR>Solution: <BR>Unfortunately, this is not a built-in feature of MATLAB, but it has been suggested to our development staff for a future release of MATLAB. </P>
<P>However, there are several workarounds available. </P>
<P>There is a function on our ftp site, called fortick.m that will accomplish this. It can be found at </P>
<P><a href="ftp://ftp.mathworks.com/pub/tech-support/solutions/s10804/" target="_blank" >ftp://ftp.mathworks.com/pub/tech-support/solutions/s10804/</A> <BR>PLEASE NOTE: This function is not officially supported by the MathWorks. It uses cell arrays, so this will only work on MATLAB 5.0 and later versions. </P>
<P>Additionally, there is another function, extendticklabel.m, available on the MATLAB Central File Exchange that performs similar tick label formatting. You can find the function at the following URL: </P>
<P><BR><a href="http://www.mathworks.com/matlabcentral/fileexchange/index.jsp" target="_blank" >http://www.mathworks.com/matlabcentral/fileexchange/index.jsp</A> </P>
<P>Perform a search using "ticklabel" as the description. This function is also not supported by the MathWorks. </P>
<P>Finally, you can use the SPRINTF function to format your tick labels using the format of your choice then set the XTickLabel or YTickLabel property of the axis to use those strings as tick labels. An example which demonstrates this is: </P>
<P>x=[1 1.53 4]; <BR>y=[1 2 3]; <BR>plot(x,y) <BR>set(gca,'XTick',x) <BR>set(gca,'XTickLabel',sprintf('%3.4f|',x)) <BR>set(gca,'YTick',y) <BR>set(gca,'YTickLabel',sprintf('%+1.2f|',y)) </P>
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-9-22 19:32 , Processed in 0.058958 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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