Matrix Dimensions do NOT agree
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
JDilla
le 7 Mai 2015
Modifié(e) : Walter Roberson
le 11 Mai 2015
%PLOTTING ARRIVAL TIMES OF DIRECT, REFLECTED & HEAD WAVE
%DEFINING VARIABLES
h=[2:10]; %Depth
v1=3500:4000; %Velocity
x=[0:40]; %Horizontal Distance
%FORMULAE FOR ARRIVAL TIMES
t_reflect = ((x.^2+4*h.^2).^0.5/v1); %Formula for arrival time
I am making some simple plots of seismic rays, modelling a reflecting rays arrival time against horizontal distance, using the formula in the code.
Initially, the distance is a range of values from 0 - 40m, and the velocity and depth are just set values.
Now, I am trying to plot the arrival time as a function of a range of velocities and as function of a range of depths at a certain point along the x axis (two subplots I suppose)
eg x=10
v1 = [2500:4000]
h = [2:10]
but obviously the matrix dimensions do not agree...any help appreciated
0 commentaires
Réponse acceptée
Star Strider
le 7 Mai 2015
If they all need to be equal length (it looks like they do), the linspace function can create them.
7 commentaires
Star Strider
le 9 Mai 2015
JDilla’s ‘Answer’ moved here...
I rather have it\two seperate plots, one for velocity range, one for depth range. Not a surf plot, how would I do this? it's not really showing the information I want.
Thanks for help
Star Strider
le 9 Mai 2015
To plot those individually (all at distance = 10):
h = linspace(2, 10, 5); %Depth
v1 = linspace(3500, 4000, 10);; %Velocity
x = linspace(0, 40, 15); %Horizontal Distance
[H,V1] = meshgrid(h, v1);
t_reflect = @(h,v1,x) (sqrt(x.^2+4*h.^2)./v1); %Formula for arrival time
T_Reflect = t_reflect(H,V1,10); % Calculate Time At x=10
figure(1)
plot(v1, T_Reflect')
grid
legdph = strsplit(num2str(h, '%.0f '),' ');
legend(legdph);
xlabel('Velocity')
ylabel('Arrival Time')
figure(2)
plot(h, T_Reflect)
grid
legvel = strsplit(num2str(v1, '%.0f '),' ');
legend(legvel, 'Location','Nw');
xlabel('Depth')
ylabel('Arrival Time')
Plus de réponses (1)
JDilla
le 10 Mai 2015
3 commentaires
Star Strider
le 11 Mai 2015
Not really. I intended it to be ‘h’. If you want the function to be of one variable only for each plot, we have to do two separate calls to ‘t_reflect’.
I initially thought you only wanted it as I wrote it in my last Comment, with only figure(2) and only with the one line. Velocity and Distance are now fixed, so the only variable is Depth. As I understand it, with only one Velocity value, figure(1) is now out of the picture.
What do you want to do with figure(1)? To get one line in it, you would have to fix a value for Depth as well, and then let Velocity vary. Fixing Depth at 5 here, and with a separate call to the function (note the lower-case variable names indicating that they are vectors and not the matrices created by meshgrid), we get:
T_Reflect_1 = t_reflect(5,v1,10); % Calculate Time At x=10, h = 5
T_Reflect_2 = t_reflect(h,3500,10); % Calculate Time At x=10, v1 = 3500
so figure(1) then becomes:
figure(1)
plot(v1, T_Reflect_1')
grid
xlabel('Velocity')
ylabel('Arrival Time')
and figure(2):
figure(2)
plot(h, T_Reflect_2)
grid
xlabel('Depth')
ylabel('Arrival Time')
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!