Passing variables from script to matlab gui directly without using base workspace

4 visualizzazioni (ultimi 30 giorni)
Hello,
I think my problem is quite simple but I cannot find an easy solution yet. I am currently trying to make a gui for several scripts I had made and I want this gui to be used by others in a very easy way i.e. I want them to just run a startup script and then only use the gui. I have a script assigned (only with its name) in a particular push button callback (grid_graph). Now inside this script, grid_graph.m the following can be seen:
Load_profiles (another script)
line_loading (another script)
code
....
...
Everything works fine and every variable from Load_profiles is properly recognised.But in the line_loading script two varialbes are generated if a certain contition occurs. Then inside the grid_graph script these appear :
if evalin('base','exist(''yellow_line'',''var'')')>0
%plot line with yellow color
else
%plot line with green color
end
If these variables are generated the gui does not recognise them and plots with green color. If I had run those scripts before using my gui the variables would be in base workspace and I could pass them one way or another. But in my case I want just the gui button to be pushed without using the base workspace. I would like to find a very effective way to pass those variables. I tried to declare them global but it didn't work out well. Also evalin wouldn't work in this case. Any ideas would be welcome, thank you very very much for your time!
  1 Commento
Kyriaki
Kyriaki il 9 Dic 2014
Eventually I found a way to do it, (probably not the most elegant though) by creating a master gui with a RUN and next button. In the RUN callback I entered whatever script whose variables needed in the base workspace and after it this code I found :
temp = who;
for iv = 1:length(temp)
assignin('base',temp{iv},eval(temp{iv}));
end
This way all script variables go directly to base workspace.So now the user is able to use only the gui itself and doesn't have to run any scripts. Thank you very much for the answers though! When I have time I will try your solutions to see if they are more efficient.

Accedi per commentare.

Risposta accettata

matt dash
matt dash il 8 Dic 2014
You should simply remove any instances of evalin('base'...) from the scripts, and call the scripts from your gui, so that the scripts evaluate in your gui function. Then store any variables you need in the handles structure and you can access them from any other function in your gui.

Più risposte (0)

Categorie

Scopri di più su Function Creation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by