필터 지우기
필터 지우기

How to invert axes?

조회 수: 11 (최근 30일)
Kathleen
Kathleen 2023년 9월 9일
댓글: Star Strider 2023년 9월 11일
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:

채택된 답변

Star Strider
Star Strider 2023년 9월 9일
편집: Star Strider 2023년 9월 10일
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
Kathleen
Kathleen 2023년 9월 10일
thank you!
Star Strider
Star Strider 2023년 9월 11일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by