Borrar filtros
Borrar filtros

How to invert axes?

11 visualizaciones (últimos 30 días)
Kathleen
Kathleen el 9 de Sept. de 2023
Comentada: Star Strider el 11 de Sept. de 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:

Respuesta aceptada

Star Strider
Star Strider el 9 de Sept. de 2023
Editada: Star Strider el 10 de Sept. de 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 comentarios
Kathleen
Kathleen el 10 de Sept. de 2023
thank you!
Star Strider
Star Strider el 11 de Sept. de 2023
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by