简体   繁体   English

在Matlab中的函数内加载文件

[英]Load a file inside a function in matlab

I have tried to load a file within a function as shown below: 我试图在函数中加载文件,如下所示:

function dy = rates(t,y)
    w= load(ang_rates) 

   for i=1:8538

          wx=w(i,1)

          dy = zeros(8538,1);   

          dy = wx+sin(phi)*tan(theta)*wy+cos(phi)*tan(theta)*wz;


      end
end

but it is giving the following error. 但它给出了以下错误。 Also it doesnot show the filename in the workspace. 此外,它也不显示工作空间中的文件名。

??? Undefined function or variable 'ang_rates'.

Error in ==> rates at 4
    data = load(ang_rates)  %# Initialize data with the .MAT file contents

Note that the file is in the same folder as the function. 请注意,该文件与该功能位于同一文件夹中。

You are probably looking for 您可能正在寻找

load('ang_rates.mat')

or the equivalent 或同等学历

load ang_rates  

In your example you try to load something with the name stored in the variable ang_rates (which of course does not exist). 在您的示例中,您尝试加载名称存储在变量ang_rates中的名称(当然不存在)。 Make sure to be ware of the difference between function syntax and command line syntax. 确保注意函数语法和命令行语法之间的区别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM