Try:

x=linspace(-5,5,25)
y = 1./x
plot(x,y)

x=linspace(-5,5,25)
y=x.^2
figure
plot(x,y)
Answer from jrand on Stack Exchange
🌐
MathWorks
mathworks.com › matlabcentral › answers › 365848-how-to-plot-x-y2
How to plot x=y2 - MATLAB Answers - MATLAB Central
November 8, 2017 - If you really want to to the work yourself, then you need to understand the nature of this function, with two branches. So you might do this instead: Fxofy = @(y) y.^2; % This function computes x, as a function of y.
🌐
MathWorks
mathworks.com › matlab › graphics › 2-d and 3-d plots › line plots
plot - 2-D line plot - MATLAB
Create plots by passing a table to the plot function followed by the variables you want to plot. When you specify your data as a table, the axis labels and the legend (if present) are automatically labeled using the table variable names. title | xlabel | ylabel | xlim | ylim | legend | hold | gca | yyaxis | plot3 | loglog ... Run the command by entering it in the MATLAB Command Window.
🌐
TutorialsPoint
tutorialspoint.com › matlab › matlab_plotting.htm
MATLAB - Plotting
x = [1 2 3 4 5 6 7 8 9 10]; x = [-100:20:100]; y = x.^2; plot(x, y) When you run the file, MATLAB displays the following plot −
Find elsewhere
🌐
MathWorks
mathworks.com › matlabcentral › answers › 347852-how-would-you-plot-y-x-2-e-x2
How would you plot y=x^(2)e^(-x2)? - MATLAB Answers - MATLAB Central
July 8, 2017 - Also, you must use element-wise operations here. See the documentation on Array vs. Matrix Operations (link) for details. Sign in to comment. ... Sign in to comment. Sign in to answer this question. ... Find the treasures in MATLAB Central and discover how the community can help you!
🌐
MathWorks
mathworks.com › matlab › get started with matlab
2-D and 3-D Plots - MATLAB & Simulink
By default, MATLAB® clears the figure each time you call a plotting function, resetting the axes and other elements to prepare the new plot. To add plots to an existing figure, use hold on. Until you use hold off or close the window, all plots appear in the current figure window. x = ...
🌐
Brown University
cfm.brown.edu › people › dobrush › am33 › Matlab › ch1 › part1.html
MATLAB TUTORIAL for the First Course. Part 1.1: Plotting
1 month ago - x=1:100; % making an array of x from 1 to 100 y1=x.^2; % defining and calculating y1 as x.^2 . NOTE: .^ opertator is used for element wise array manupulation y2=(x.^3)/100; % defining and calculating y2 as (x.^3)/100 figure % opens new figure plot(x,y1) % plots the first graph of x-y1 figure % opens second new figure plot(x,y2) % plots the second graph of x-y2 · There is a special subroutine multigraf.m that allows one to place up to six Matlab figures on one page.
🌐
Control Tutorials
ctms.engin.umich.edu › CTMS › index.php
Control Tutorials for MATLAB and Simulink - Extras: Plotting in MATLAB
Using y2 = 2*exp(5*t)-1;, the following plot results. Use the Plot Browser on the right side of the plot to select which data should be displayed. If you have sub-plots, you can also select or deselect which ones should be displayed. Of course this is not a complete account of plotting with ...
🌐
Unisa
lo.unisa.edu.au › mod › book › view.php
MATLAB: Plotting Graphs | learnonline
Example 2: By using hold on and hold off, you can plot several functions on the same axes using a number of plot commands. The functions f(x) = x2 and f−1(x) = √x are inverse functions for x ≥ 0 and hence their graphs must be reflections through the line y = x. Execute the following M-file, ...
Top answer
1 of 3
19

You can do something like the following. In comparison to the solution of @Benoit_11 I do use the normal Matlab labels and refer to both axes with handles so the assignments are explicit.

The following code creates an empty x-axis b with the units m/s with a negligible height. After this, the actual plot is drawn in a second axes a located a bit above the other axes and with units km/h. To plot on a specific axes, insert the axes-handle as the first argument of stem. The conversion from m/s to km/h is directly written in the call to stem. Finally, it's needed to set the xlim-property of the both axes to the same values.

% experimental data
M(:,1) = [ 0,  1,  2,  3,  4,  5];
M(:,3) = [12, 10, 15, 12, 11, 13];

% get bounds
xmaxa = max(M(:,1))*3.6;    % km/h
xmaxb = max(M(:,1));        % m/s


figure;

% axis for m/s
b=axes('Position',[.1 .1 .8 1e-12]);
set(b,'Units','normalized');
set(b,'Color','none');

% axis for km/h with stem-plot
a=axes('Position',[.1 .2 .8 .7]);
set(a,'Units','normalized');
stem(a,M(:,1).*3.6, M(:,3));

% set limits and labels
set(a,'xlim',[0 xmaxa]);
set(b,'xlim',[0 xmaxb]);
xlabel(a,'Speed (km/h)')
xlabel(b,'Speed (m/s)')
ylabel(a,'Samples');
title(a,'Double x-axis plot');
2 of 3
9

As a very simple alternative you could also create a 2nd axis (transparent) and put it below the first one so that you only see the x axis.

Example:

clear
clc
close all

x = 1:10;

x2 = x/3.6;

y = rand(size(x));

hP1 = plot(x,y);

a1Pos = get(gca,'Position');

%// Place axis 2 below the 1st.
ax2 = axes('Position',[a1Pos(1) a1Pos(2)-.05 a1Pos(3) a1Pos(4)],'Color','none','YTick',[],'YTickLabel',[]);

%// Adjust limits
xlim([min(x2(:)) max(x2(:))])

text(2.85,0 ,'m/s','FontSize',14,'Color','r')
text(2.85,.05 ,'km/h','FontSize',14,'Color','r')

Output:

Then you can manually add the x labels for each unit, in different color for example.

🌐
MathWorks
mathworks.com › matlabcentral › answers › 311152-how-to-plot-x-f-y
How to plot x=f(y) ? - MATLAB Answers - MATLAB Central
November 8, 2016 - It rather foolishly insists on putting x and y on their respective axes. We could as easily have done the work the hard way, using plot directly. But why bother? Sign in to comment. ... Sign in to comment. Sign in to answer this question. Mathematics and Optimization Symbolic Math Toolbox Mathematics Calculus · Find more on Calculus in Help Center and File Exchange ... Find the treasures in MATLAB ...
🌐
MathWorks
mathworks.com › matlab › graphics › labels and styling › axes appearance
Display Data with Multiple Scales and Axes Limits - MATLAB & Simulink
For example, you can create two plots that have different x- and y-axis limits. First, create two sets of x- and y-coordinates. x1 = 0:0.1:40; y1 = 4.*cos(x1)./(x1+2); x2 = 1:0.2:20; y2 = x2.^2./x2.^3;