How to fix 'Undefined function or variable 'temp' in ode45'.

My code below gives me the error
Undefined function or variable 'temp'.
when using the command
[t,u] = ode45(@temp,[0,20],[20]);
which I intent to create a graph with. As a note, I used 'global' to define and then set the values of my constants.
If necessary, the purpose of this code is to create a graph for a CPU temperature based on data from a lab.

 Risposta accettata

James Tursa
James Tursa il 23 Feb 2017
Modificato: James Tursa il 23 Feb 2017
Where is the file temp.m located? Is it in the current directory or on the MATLAB path? Is it a sub-function? The error indicates MATLAB does not see the file temp.m from where you call ode45.

4 Commenti

It's just on my desktop; hasn't been moved but I had a similar problem before. I'll quickly change this and see if it works
I think you may be correct as it doesn't appear to have the correct file path however, I do not know how to define the location of the file 'temp.m' for the code.
Ahah! Found out how, set it all and it's working! Thank you so much for you help, I really appreciate it.
As an extra note for others who may have the problem though. I fixed it by setting a new 'Search Path'. In Matlab; Home>Set_Path>Add_Folder.

Accedi per commentare.

Più risposte (1)

You have not stored the code in temp.m or temp.m is not on your path.
Note: global variables are the slowest kind of variables. You should avoid them. See https://www.mathworks.com/help/matlab/math/parameterizing-functions.html

Categorie

Scopri di più su Programming in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by