Multiple input values for same function and plot them?

Hello,
I was wondering if there was a quick clean and easy way to make a function input multiple values of x, such as 0, .25 ,.5, .75, 1 and then plot these five curves out on the same plot. I know how to do it manualy by create 5 different functions and naming them slightly differently, but I was wondering if there was a quicker/cleaner way of doing it?

4 件のコメント

Image Analyst
Image Analyst 2019 年 11 月 27 日
Those are 5 scalars, not 5 functions or curves. You can use "hold on" to plot multiple curves on one plot.
plot(x1, y1);
hold on;
plot(x2, y2);
plot(x3, y3);
Adam Danz
Adam Danz 2019 年 11 月 28 日
In plot(x,y), if x and y are matricies, a line will be drawn for each column of the inputs. There are additional ways to get multiple lines out of one set of inputs and that's all examples in the documentation.
Hedayat
Hedayat 2019 年 11 月 28 日
You can use plot in one statement
plot(X1,Y1,...,Xn,Yn) plots multiple X, Y pairs using the same axes for all lines.
KSSV
KSSV 2019 年 11 月 28 日
MAke the input as amtrix and plot in one strectch.

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

回答 (1 件)

KSSV
KSSV 2019 年 11 月 28 日

0 投票

A = [10 20 30 405 50] ;
th = linspace(0,2*pi) ;
X = zeros(length(A),length(th)) ;
for i = 1:length(A)
X(i,:) = A(i)*sin(th) ;
end
plot(th,X)

1 件のコメント

Adam Danz
Adam Danz 2019 年 11 月 28 日
You could replace the loop with
X = A(:) * sin(th)

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

カテゴリ

タグ

質問済み:

2019 年 11 月 25 日

コメント済み:

2019 年 11 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by