2013-03-27 19 views
0

我有一個名爲motor_model.m的m文件。我有另一個名爲controller.m的m文件,我在第一行中調用motor_model.m。現在,motor_model.m的輸出是穩態電流,它存儲在名爲I_steadystate的變量中,該變量的值需要在controller.m中調用。將一個m文件中變量的值調用到另一個m文件中

你能告訴我如何做到這一點的代碼?

+1

難道這些腳本文件或功能? – 2013-03-27 18:11:56

+0

腳本文件。我該怎麼辦? – user2216885 2013-03-27 18:39:47

+0

在腳本文件中,您不需要執行任何操作。只需按名稱使用變量就好像每個文件都在一個文件中一樣。 – 2013-03-27 19:02:42

回答

0

在M檔Controller.m或者:

function [] = controller() 
steadyState = motor_model() 

在M檔motor_model.m

function [I_steadystate] = motor_model() 
I_steadystate = 0; % 0 is an example. I_steadyState should be defined somewhere in your code. 
+0

這是否需要我在controller.m中調用motor_model.m – user2216885 2013-03-27 18:35:46

+0

是的,但是您已經說過,您在第一行執行該操作......但是,這會將您的腳本轉換爲[函數](http:// www.mathworks.co.uk/help/matlab/ref/function.html)(另見[this](http://www.mathworks.co.uk/help/matlab/matlab_prog/scripts-and-functions.html ))。 – wakjah 2013-03-28 08:10:45

相關問題