How to set the range of X axis equal to a column vector

4 次查看(过去 30 天)
Hello,
I want to creat a plot with two x axis (first one in the bottom and second one in the top) . I want to set the range of the seconde axis equal to a column array (x2) (the first point in the x xis = first element in x2). I write the following code;
However, the result plot is not what I need ( I want the second axis starts from the first element of x2 but it starts from the last elemnts). Furtheremore, I don't need the second y axis. How should I correct my code in order to get the result that I want.
I have attached the data for x2 and the result plot
Thanks for you help,plot.jpg
figure
line (X, Y)
ax1 = gca; % current axes
ax1_pos = ax1.Position; % position of first axes
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','non');
line(x2,ax2,'Color','r')

采纳的回答

Jan
Jan 2019-1-16
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','top',...
'XLim', [0.8, 1.35], ...
'XDir', 'reverse', ...
'YTick', [], ... % No ticks on Y axis
'Color','non');
Or set the XTick and XTickLabel manually.
  2 个评论
Sara
Sara 2019-1-16
Thanks for yor answer, the plot is what I need, However, I think I've described my question wrongly,
I need to set one y value to 2 x value (x1=number of cycle and x2=time) and show it in one plot. for example when y= i I can specify the corresponding cycle and time (x1 and x2). How can I do it.
Jan
Jan 2019-1-16
I do not understand what "set one y value to 2 x value" means. "x1=number of cycle and x2=time" is not clear also: What is "number of cycle"? What do you want to show in one plot? In "y=i", what is "i"? Where do you "specify the corresponding cycle and time"?
I do not understand, which problem you want to solve. Please post a small example with inputs and explain the wanted output.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by