File run from pushbutton not using updated workspace values as inputed in a GUI
3 views (last 30 days)
Show older comments
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')
0 Comments
Accepted Answer
Jan
on 1 Jul 2013
Edited: Jan
on 1 Jul 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 Comments
Jan
on 1 Jul 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.
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!