How to invert axes?

9 views (last 30 days)
Kathleen
Kathleen on 9 Sep 2023
Commented: Star Strider on 11 Sep 2023
Hi Everyone,
I have the following code but my plots are not looking like what I need.
I attached the example of how the graphs should look like as well.
Thanks!
Exercise 1.3 Kathleen
clear, clc, close all
%number and location of seismometer depths (change n to 4 for the part (e)).
n=100;
%n=4;
z=linspace(0,20,n+1)';
z=z(2:end);
Deltaz=z(2)-z(1);
%velocity gradient
g=40;
%velocity at z=0;
v0=1000;
%true velocity at midpoints
v=v0+(z-Deltaz/2)*g;
%true slowness
s=1./v;
%perfect data (analytic solution)
t=(1/g)*(log(v0+z*g)-log(v0));
%G matrix
G=tril(ones(n,n))*Deltaz;
figure(1)
plot(z,t,'k',z,G*s,'r-.')
xlabel('Depth (m)')
ylabel('Travel Time (s)')
legend('Analytical','Discretized','location','southeast')
figure(2)
plot(z,s,'k',z,G\t,'r-.')
xlabel('Depth (m)')
ylabel('Slowness (m/s)')
legend('m_{true}’,’m')
title('Noise-free Solution')
%add noise to the travel time data vector
tn=t+0.00005*randn(size(t));
figure(3)
plot(z,s,'k',z,G\tn,'r-.')
xlabel('Depth (m)')
ylabel('Slowness (m/s)')
legend('m_{true}’,’m')
title('Noisy Solution')
The graphs needed are:

Accepted Answer

Star Strider
Star Strider on 9 Sep 2023
Edited: Star Strider on 10 Sep 2023
I believe what you want is Reverse
x = linspace(0, 1);
y = exp(-(x-0.5).^2*50);
figure
plot(x, y)
grid
figure
plot(x, y)
grid
Ax = gca;
Ax.YDir = 'Reverse';
EDIT —
See the documentation section on Axes Properties for a list of all of them.
EDIT — (10 Sep 2023 at 10:33)
Applying that here —
clear, clc, close all
%number and location of seismometer depths (change n to 4 for the part (e)).
n=100;
%n=4;
z=linspace(0,20,n+1)';
z=z(2:end);
Deltaz=z(2)-z(1);
%velocity gradient
g=40;
%velocity at z=0;
v0=1000;
%true velocity at midpoints
v=v0+(z-Deltaz/2)*g;
%true slowness
s=1./v;
%perfect data (analytic solution)
t=(1/g)*(log(v0+z*g)-log(v0));
%G matrix
G=tril(ones(n,n))*Deltaz;
figure(1)
plot(z,t,'k',z,G*s,'r-.')
Ax = gca;
Ax.YDir = 'Reverse';
xlabel('Depth (m)')
ylabel('Travel Time (s)')
legend('Analytical','Discretized','location','southeast')
figure(2)
plot(z,s,'k',z,G\t,'r-.')
Ax = gca;
Ax.YDir = 'Reverse';
xlabel('Depth (m)')
ylabel('Slowness (m/s)')
legend('m_{true}’,’m')
title('Noise-free Solution')
%add noise to the travel time data vector
tn=t+0.00005*randn(size(t));
figure(3)
plot(z,s,'k',z,G\tn,'r-.')
Ax = gca;
Ax.YDir = 'Reverse';
xlabel('Depth (m)')
ylabel('Slowness (m/s)')
legend('m_{true}’,’m')
title('Noisy Solution')
.
  2 Comments
Kathleen
Kathleen on 10 Sep 2023
thank you!
Star Strider
Star Strider on 11 Sep 2023
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!