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

조회 수: 5 (최근 30일)
Sara
Sara 2019년 1월 16일
댓글: Jan 2019년 1월 16일
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에서 Formatting and Annotation에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by