필터 지우기
필터 지우기

Static workspace assignment.

조회 수: 6 (최근 30일)
Kaushik
Kaushik 2012년 2월 7일
댓글: Michelle Ballard 2014년 3월 17일
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);
  댓글 수: 1
Kaushik
Kaushik 2012년 2월 7일
"var_name" is the first variable in the 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