Borrar filtros
Borrar filtros

Static workspace assignment.

6 visualizaciones (últimos 30 días)
Kaushik
Kaushik el 7 de Feb. de 2012
Comentada: Michelle Ballard el 17 de Mzo. de 2014
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 comentario
Kaushik
Kaushik el 7 de Feb. de 2012
"var_name" is the first variable in the init_file.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 7 de Feb. de 2012
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 comentarios
Kaushik
Kaushik el 8 de Feb. de 2012
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 el 17 de Mzo. de 2014
(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.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by