Azzera filtri
Azzera filtri

How to invert axes?

11 visualizzazioni (ultimi 30 giorni)
Kathleen
Kathleen il 9 Set 2023
Commentato: Star Strider il 11 Set 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:

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by