Defining variables inside of a function

11 Ansichten (letzte 30 Tage)
Khalid Sherif
Khalid Sherif am 7 Okt. 2018
Kommentiert: madhan ravi am 7 Okt. 2018
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.

Akzeptierte Antwort

madhan ravi
madhan ravi am 7 Okt. 2018
Bearbeitet: madhan ravi am 7 Okt. 2018
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 Kommentare
Khalid Sherif
Khalid Sherif am 7 Okt. 2018
Bearbeitet: Khalid Sherif am 7 Okt. 2018
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 am 7 Okt. 2018
not sure what your teacher meant

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Stephen23
Stephen23 am 7 Okt. 2018
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