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.

 Respuesta aceptada

James Tursa
James Tursa el 23 de Feb. de 2017
Editada: James Tursa el 23 de Feb. de 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 comentarios

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.

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 23 de Feb. de 2017
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

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Preguntada:

el 22 de Feb. de 2017

Comentada:

el 23 de Feb. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by