MATLAB Answers

Multiple input values for same function and plot them?

조회 수: 13(최근 30일)
Gaetano Dona-Jehan
Gaetano Dona-Jehan 25 Nov 2019
Commented: Adam Danz 28 Nov 2019
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

표시 이전 댓글 수: 1
Adam Danz
Adam Danz 28 Nov 2019
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 28 Nov 2019
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 28 Nov 2019
MAke the input as amtrix and plot in one strectch.

로그인 to comment.

답변 수 (1)

KSSV
KSSV 28 Nov 2019
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 28 Nov 2019
You could replace the loop with
X = A(:) * sin(th)

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

태그


Translated by