Matlab x轴缩放-均匀间隔的自定义轴 [英] Matlab x-axis scaling – evenly spaced custom axis

查看:1018
本文介绍了Matlab x轴缩放-均匀间隔的自定义轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下变量,我需要在x轴上绘制数据(x_values,y_values),并在"x_labels"值处打勾.每个"x_labels"刻度都必须在x轴上均匀分布(例如1厘米).

Using the variables below, I need to plot data (x_values, y_values) on an x axis with ticks at ‘x_labels’ values. Each ‘x_labels’ tick must be evenly spaced on the x-axis (e.g. 1 cm).

我一直在使用'XTick'和'XTickLabel'变量,尽管我在线搜索了所有其他示例,但这些示例都与'x_labels'和'x_values'相同时有关.这里的挑战是"x_labels"和"x_values"之间的间距不同.请帮忙!

I have been playing with 'XTick' and 'XTickLabel' variables and although I searched online all other examples are related to when the ‘x_labels’ and ‘x_values’ are identical. The challenge here is that there is different spacing between ‘x_labels’ and ‘x_values’. Please help!

x_labels = [4 8 16 32 64 128];
x_values = [5 10 35 50 60 70 90 120];
y_values = rand(1,length(x_values))

谢谢!

推荐答案

使用 xTick和轴的xTickLabel (链接底部附近)属性,xTick定义刻度线位置,xTickLabel定义标签.
因此,在绘制数据之后:

Using the set command you can specify the xTick and xTickLabel (near the bottom of the link) properties of the axis separately, xTick defines the tick marks locations and xTickLabel defines the labels.
So after plotting the data:

plot(x_values,y_values);

我们可以自由设置位置,在此示例中,它们在零和x_values的最大值之间均匀间隔.然后,使用set命令设置轴属性,( gca 是当前的轴手柄)

we can freely set the locations, in this example they are spaced evenly between zero and the max of x_values. The set command is then be used to set the axis properties, (gca is the current axis handle)

x_label_locations = linspace(0,max(x_values),numel(x_labels));

set(gca,'xTick',x_label_locations,'xTickLabel',x_labels)

这篇关于Matlab x轴缩放-均匀间隔的自定义轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆