Plot using array for different plot lines?
Mostrar comentarios más antiguos
I'm trying to figure out how to make a reusable formula that will plot different lines based on a value set stored in an array. Right now I'm manually running this. The last portion of the equation has a ratio that I'd like to change and add a new plot for each value.
x = 0:1:90; %plot theta 0-90 in 1 degree increments
V = 5; % Use 5 for V since that's what's given in p.75
D = .1; % Use .1m for D since that's what's given in p.75
% Plot 0 d/D ratio. No, hole.
y0 = 1000 * V ^ 2 * (pi / 4) * D ^2 * (1 + sind(x)) * (1 - (0) ^ 2);
% Plot .25 d/D ratio. 25mm hole.
y1 = 1000 * V ^ 2 * (pi / 4) * D ^2 * (1 + sind(x)) * (1 - (0.25) ^ 2);
% Plot .5 d/D ratio. 50mm hole.
y2 = 1000 * V ^ 2 * (pi / 4) * D ^2 * (1 + sind(x)) * (1 - (0.5) ^ 2);
% Plot .75 d/D ratio. 75mm hole.
y3 = 1000 * V ^ 2 * (pi / 4) * D ^2 * (1 + sind(x)) * (1 - (0.75) ^ 2);
% Plot 1 d/D ratio. 100mm hole.
y4 = 1000 * V ^ 2 * (pi / 4) * D ^2 * (1 + sind(x)) * (1 - (1) ^ 2);
plot(x,y0,x,y1,x,y2,x,y3,x,y4);
So, I'm looking for something like this.
x = 0:1:90; %plot theta 0-90 in 1 degree increments
V = 5; % Use 5 for V since that's what's given in p.75
D = .1; % Use .1m for D since that's what's given in p.75
r = 0:.25:1
y = 1000 * V ^ 2 * (pi / 4) * D ^2 * (1 + sind(x)) * (1 - (r) ^ 2);
Then have MATLAB plot the 5 different values of the r array as separate plot lines. I'm new to MATLAB but not to programming. Any literature or a point in the right direction would be great. Thanks!
Respuesta aceptada
Más respuestas (1)
You have to make y a matrix.
x = 0:1:90; %plot theta 0-90 in 1 degree increments
V = 5; % Use 5 for V since that's what's given in p.75
D = .1; % Use .1m for D since that's what's given in p.75
r = 0:.25:1 ;
y = zeros(length(r),length(x)) ; % initialization
for i = 1:length(r)
y(i,:) = 1000*V^2*(pi/4)*D ^2*(1+sind(x))*(1 - r(i)^ 2);
end
plot(x,y) ;
1 comentario
Emiliano Jordan
el 27 de Sept. de 2016
Categorías
Más información sobre Line Plots en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!