range matlab,correct axis range (matlab)

问题

how can i solve the problem of these two images automatically (with a code adaptable to different data) without having to fix the axes range for each plot (i have millions of these plots)?

problem: axis range should be smaller

problem: axis range should be bigger

also, i need axis to be correctly labeled from the first value to last (see example in comment please)

any help is highly appreciated. thank you so so much.

回答1:

In order to have a complete bounding box use box on.

In order to avoid large empty space around a plot (or no space at all) use xlim and ylim. Try the following:

figure

plot(x,y)

box on

x1 = min(x);

x2 = max(x);

dx = x2-x1;

y1 = min(y);

y2 = max(y);

dy = y2-y1;

fc = 10/100 % this is a factor of 10% of empty space around plot

xlim([x1-dx*fc x2+dx*fc])

ylim([y1-dy*fc y2+dy*fc])

If you want to have a tick value appear at the start and the end of the axis, you could either force it by set(gca,'Xtick',[values]), where values are those ticks you want to show; or by floor and ceil of the xlim and ylim min and max limits above.

Hope this is what you need

回答2:

To set axis limit and visualize chart better you can use axis command like axis([xmin xmax ymin ymax]) where parameters set chart borders. It should help you. More information is here:

http://www.mathworks.se/help/matlab/ref/axis.html

来源:https://stackoverflow.com/questions/13408648/correct-axis-range-matlab

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值