Error on 'axes' parameters
显示 更早的评论
I am receiving the following error probably referring to 'XLim' or 'YLim' as 'axes' parameters:
Error using axes
Value must be a 1x2 vector of numeric type in which the second element is larger than the first and may be Inf
I checked my workspace and everything seems fine since 'XLim' is a 1x2 datetime vector and 'YLim' is a 1x2 numeric vector with their 'min limit' < 'max limit'.
The related code is the following:
ax1 = gca;
ax1_Pos = ax1.Position;
ax1_XLim = ax1.XLim;
ax1_YLim = ax1.YLim;
ax1_start = ax1.XLim(1);
%ax1_end = ax1.XLim(2);
xticks([ax1_start, time_dat(51-1), time_dat(86-1), time_dat(129-1), time_dat(170-1)]);
ax2_labels = {'z_acc_test','setup1','y_acc_test','setup2','x_acc_test'};
ax2 = axes('Position', ax1_Pos, 'XLim', ax1_XLim, 'YLim', ax1_YLim, 'XAxisLocation', 'top', 'YAxisLocation', 'right', 'XTick', xticks, 'XTickLabel', ax2_labels);
采纳的回答
更多回答(1 个)
Vasileios Leivadas
2018-7-13
4 个评论
Adam Danz
2018-7-13
The comment in my original answer suggested it was the xticks but in addition to that, your axis limits were also incorrect since you were using datetime values to set the limits.
Regarding your new problem, why do you need to create a second axis over top of the first one?
Vasileios Leivadas
2018-7-14
I see. You need to add this to your axes()...
ax2 = axes( ..., 'Color', 'None', ... );
That will make the 2nd axis transparent so you can see axis 1 as well.
Vasileios Leivadas
2018-7-16
类别
在 帮助中心 和 File Exchange 中查找有关 Axes Appearance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

