Matlab x轴缩放-均匀间隔的自定义轴

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)