Plotting Multiple Curves on the Same Graph

1 回表示 (過去 30 日間)
Hollis Williams
Hollis Williams 2019 年 7 月 16 日
コメント済み: Star Strider 2019 年 7 月 18 日
I am plotting a graph of radial velocity against varying radius, but there is also a parameter in the velocity expression similar to the Reynolds number which can have various values, so I would like to set the value of the parameter to 0, 1 and 0.2 and to plot three curves on the same graph, what would be the easiest way to do this?
  1 件のコメント
Adam
Adam 2019 年 7 月 16 日
doc hold
Set e.g.
hold( hAxes, 'on' )
for your axes with handle hAxes, then you can add as many plots as you like.
Alternatively if you have all the results together in a matrix (assuming they are the same length for each parameter) you can just plot the matrix all in one go using
doc plot
and making sure you have it oriented the right way.

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2019 年 7 月 16 日
It depends on your function and what you want to do:
t = linspace(0, 2*pi);
freq = [1 5 9];
ampl = [1 2 3];
s = bsxfun(@times, ampl(:), sin(freq(:)*t));
figure
plot(t, s)
grid
  6 件のコメント
Hollis Williams
Hollis Williams 2019 年 7 月 18 日
Many thanks for your answer, I have tried something slightly different but getting a bit of an unexpected error message. So now I am trying:
bt = @(Kn) -sqrt(pi/2)*(30*Kn.^2 + 180*(1+(1./pi))*Kn.^3)./(20*pi + 135*pi*Kn + 9*(25*pi +18)*Kn.^2 +324*Kn.^3);
theta = @(R,Kn) (bt./(R.^2));
Knv = [0, 0.2, 1];
Rv = 1:10;
[Rm,Knm] = meshgrid(Rv,Knv);
figure
plot(Rv, theta(Rm,Knm))
grid
%xlabel('R')
lgdc = sprintfc('K_n = %3.1f', Knv);
legend(lgdc, 'Location','SE')
I seem to get an error message related saying that the ./ in the expression for theta is an undefined operator for input arguments of type 'function_handle', although I have used it elsewhere with no problems.
Star Strider
Star Strider 2019 年 7 月 18 日
As always, my pleasure!
Remember that in my code, ‘bt’ is a function, so it needs to be evaluated in any calculation using it, and that requires that it be supplied with a numeric argument so that it can return a numeric result:
theta = @(R,Kn) (bt(Kn)./(R.^2));
The complete code is now:
bt = @(Kn) -sqrt(pi/2)*(30*Kn.^2 + 180*(1+(1./pi))*Kn.^3)./(20*pi + 135*pi*Kn + 9*(25*pi +18)*Kn.^2 +324*Kn.^3);
theta = @(R,Kn) (bt(Kn)./(R.^2));
Knv = [0, 0.2, 1];
Rv = 1:10;
[Rm,Knm] = meshgrid(Rv,Knv);
figure
plot(Rv, theta(Rm,Knm))
grid
%xlabel('R')
lgdc = sprintfc('K_n = %3.1f', Knv);
legend(lgdc, 'Location','SE')
I tested that to be sure it works. It does.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by