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.

 채택된 답변

James Tursa
James Tursa 2017년 2월 23일
편집: James Tursa 2017년 2월 23일

0 개 추천

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

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.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 2월 23일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2017년 2월 22일

댓글:

2017년 2월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by