Filter löschen
Filter löschen

How to invert axes?

11 Ansichten (letzte 30 Tage)
Kathleen
Kathleen am 9 Sep. 2023
Kommentiert: Star Strider am 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:

Akzeptierte Antwort

Star Strider
Star Strider am 9 Sep. 2023
Bearbeitet: Star Strider am 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 Kommentare
Kathleen
Kathleen am 10 Sep. 2023
thank you!
Star Strider
Star Strider am 11 Sep. 2023
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by