如何在matlab图中放置标签和分隔符

时间:2017-09-13 09:03:33

标签: matlab graph

我有一个图表,显示三轴加速度计的数据,时间如下

M_acc(:,1) = X_Axis_acc;
M_acc(:,2) = Y_Axis_acc;
M_acc(:,3) = Z_Axis_acc;

figure
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
plot(time_acc,M_acc);
xlabel('Time[s]','FontSize', 15);
ylabel('Value[deg/s]','FontSize', 15);
h = legend('location','best','X-Axis', 'Y-Axis', 'Z-Axis');
set(h, 'FontSize', 15);
title('Accelerometer')

我还有我想要放置分隔符的点列表,标签为:

M_ant(:,1) = t_start;
M_ant(:,2) = t_stop;
M_ant(:,3) = State;

我想要的是拥有数字而不是以下内容:

Graph I have

类似于此:

Graph I want

可能类似吗?

1 个答案:

答案 0 :(得分:1)

您可以使用text来显示标签以及hold onplot的组合,以添加分隔符,如下所示:

% Create random data with peaks at 30 and 60
X = rand(100, 1);
X(30) = -1;
X(60) = -2;

% generate the plot separators and labels
figure
plot(X);
hold on
plot([20 20 70 70], [X(20) -3 -3 X(70)], 'k', 'LineWidth', 3)
plot([30 30], [X(30) -3], 'k', 'LineWidth', 3)
text(25,-2.9,'1')
plot([60 60], [X(60) -3], 'k', 'LineWidth', 3)
text(45,-2.9,'2')
text(65,-2.9,'3')

enter image description here