Borrar filtros
Borrar filtros

File run from pushbutton not using updated workspace values as inputed in a GUI

1 visualización (últimos 30 días)
Hi,
I've made a GUI using GUIDE which takes values from an initial parameters sheet, allows a user to edit them and then runs the initial parameters file again with these new variables.
The file should then calculate a few variables (which aren't available to be edited by the user) using the new, user selected values.
The GUI displays the original values fine, and when I click a 'save' button I can see that the newly selected values are saved into the workspace.
However, if I then click a 'calculate' button the equations in the file give the same values as the start.
This isn't due to re-initialising the variables back to their original value when the file is run, as I have added a couple of
if (exist(var1)==1)
var1=var1;
else
var1=5;
end
where 5 is the original value, and the variables aren't switching back to their original ones as they were before i put these loops in.
If I exit the GUI and then run the file it does use the saved, user inputed values and the calculations change.
When I run it using the GUI, it says that the variables aren't defined, even when they're in the workspace... Which doesn't make any sense to me, because it's happy to take the values from the workspace when run normally (not through GUI)
Why aren't the equations using the new, saved values in the workspace when I run it from the GUI?
Thanks!
The code in the calculate callback is simply:
run('initial_parameters.m')

Respuesta aceptada

Jan
Jan el 1 de Jul. de 2013
Editada: Jan el 1 de Jul. de 2013
Do you mean:
if exist('var1', 'var') == 1
The line var1 = var1 does not do anything. What is its purpose?
You can start a script by using its name:
initial_parameters;
So you neither need "run" nor the file extension ".m".
  2 comentarios
Henry
Henry el 1 de Jul. de 2013
ooh, maybe I've misunderstood how to use the exist function, I thought that using it this way would check to see if it existed, and if it did give an output of 1, is this not correct?
I was using the var1=var1 to see if that took the value from the workspace, but hadn't worked.
having fiddled with it a little, it seems like although the workspace has the saved new value, the equation is using the previous one, would this be down to my incorrect usage of exist?
thanks
Jan
Jan el 1 de Jul. de 2013
exist checks, if the following string is known as a variable, file, folder etc. If the 2nd input is defined, here as 'var', exist replies TRUE if the string is a known variable.
var1=var1 assigns the variable var1 to the variable var1. I assume there is a confusion concerning the nature of a "workspace". Each function has its own workspace and initially this workspace is empty. To keep values from an earlier call, you need to define the variable as persistent (see: doc persistent). The best method to forward the contents of variables to another function is using inputs and outputs.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by