Plot function with changing variables

5 Ansichten (letzte 30 Tage)
Katie Fox
Katie Fox am 29 Sep. 2019
Kommentiert: Star Strider am 29 Sep. 2019
for v = 5:20 d = 20:120
w = (0.25*pi*(d.^2)*0.5*(v.^2))
plot(v,w)
hold on
end
% I am trying to plot v on the x axis, w on the y and vary the variable v between 5 and 20 and d between 20 and 120. I am new to Matlab why won't the graph appear? It just shows a blank white sceen?

Akzeptierte Antwort

Star Strider
Star Strider am 29 Sep. 2019
The plot function plots lines between two points. You appear to be plotting points, so you need to plot markers.
Try this:
for v = 5:20
for d = 20:120
w = (0.25*pi*(d.^2)*0.5*(v.^2));
plot(v,w,'.')
hold on
end
end
Experiment to get the result you want.
  2 Kommentare
Katie Fox
Katie Fox am 29 Sep. 2019
Thank you, is there a way to connect the points for a given value for d? I am hoping to end up with 120 lines based on the variable d?
Star Strider
Star Strider am 29 Sep. 2019
As always, my pleasure!
I am hoping to end up with 120 lines based on the variable d?
Try this:
d = 20:120;
v = 5:20;
[V,D] = ndgrid(v, d);
w = @(v,d) (0.25*pi*(d.^2)*0.5.*(v.^2));
figure
plot(D, w(V,D))
xlabel('d')
ylabel('w')
Note that here ‘d’ only has 101 values, not 120.
Experiment to get the result you want.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by