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

3 Ansichten (letzte 30 Tage)
Sara
Sara am 16 Jan. 2019
Kommentiert: Jan am 16 Jan. 2019
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')

Akzeptierte Antwort

Jan
Jan am 16 Jan. 2019
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 Kommentare
Sara
Sara am 16 Jan. 2019
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 am 16 Jan. 2019
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Formatting and Annotation finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by