Static workspace assignment.

6 次查看(过去 30 天)
Hi,
I'm getting following error when i run a 'calibration file' inside a function called "RSI_file". The "init_file" contains values of various variables, i need to create a table with min/max values of each variable and the calibration values taken from this file. I've succeeded in obtaining the min/max values, but running this file inside a function is giving error. Can someone please help me out?
ERROR -
Attempt to add "<var_name>" to a static workspace. See MATLAB Programming, Restrictions on Assigning to Variables for details.
Error in ==> RSI_file at 217 run(init_file);

采纳的回答

Walter Roberson
Walter Roberson 2012-2-7
If you must do that, then remove the final 'end' statement from the RSI_file function. This would require removing the final 'end' statement from all other functions in the same file, and would also disallow you from using nested functions.
Alternately, leave all the 'end' statements the way they are, but initialize all those variables (to anything) before the run() call so that they have slots in the static workspace.
  2 个评论
Kaushik
Kaushik 2012-2-8
Thanks Walter. it worked perfectly. will also try to implement it with the second method that you suggested. but i think it'll be difficult to initialize those variables, as i'm getting them from init file only.
Thanks again.
Michelle Ballard
Michelle Ballard 2014-3-17
(I know this is a bit old, but I wanted to add to it in case someone else comes here since this was first in Google)
What Walter meant by initialize the variables, is to create the memory space for them. You don't have to know what value the variable has, just the name.
Example: I have a file "limits.mat" that contains min and max values that were used for a test apparatus. I can change them at any time on test stand, but the names are the same every time.
Let's say the file contains
  • Item one VoltMin = 3.0;
  • Item two VoltMax = 12.5;
  • Item three VoltStep = 0.5;
In my function, I would simply initialize the variables as
  • Item one VoltMin = [];
  • Item two VoltMax = [];
  • Item three VoltStep = [];
Then when you load the file, and you won't have the error anymore. This worked for me when loading a data structure as well.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by