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
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 件のコメント
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 Center および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!