Defining variables inside of a function

조회 수: 11 (최근 30일)
Khalid Sherif
Khalid Sherif 2018년 10월 7일
댓글: madhan ravi 2018년 10월 7일
t = 0:0.1:2; y(t) = cos(2*t); Array indices must be positive integers or logical values.
My problem here is that I want to have the variable "t" known inside the parentheses beside "y" as a regular written function in Matlab but I can't figure it out I tried searching for it online and found nothing.

채택된 답변

madhan ravi
madhan ravi 2018년 10월 7일
편집: madhan ravi 2018년 10월 7일
syms y(t)
y(t) = cos(2*t)
t = 0:0.1:2;
y=double(subs(y))
OR
y =@(t) cos(2*t) %Not sure which one you want but both gives the same results
y(t)
  댓글 수: 4
Khalid Sherif
Khalid Sherif 2018년 10월 7일
편집: Khalid Sherif 2018년 10월 7일
There is also another way that I am not sure of, my teacher said (just a part of it) that I could define it by typing this y:( ) but the problem he didn't continue what I should be typing inside of the parentheses
madhan ravi
madhan ravi 2018년 10월 7일
not sure what your teacher meant

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Stephen23
Stephen23 2018년 10월 7일
t = 0:0.1:2;
y = cos(2*t);

Community Treasure Hunt

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

Start Hunting!

Translated by