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 件のコメント

Jason Clifton
Jason Clifton 2017 年 2 月 23 日
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
Jason Clifton
Jason Clifton 2017 年 2 月 23 日
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.
Jason Clifton
Jason Clifton 2017 年 2 月 23 日
Ahah! Found out how, set it all and it's working! Thank you so much for you help, I really appreciate it.
Jason Clifton
Jason Clifton 2017 年 2 月 23 日
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 ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by