GUI issues -> 1) memory: assignin, getappdata/setappdata and handles 2) best programming practices

1 vue (au cours des 30 derniers jours)
Hi,
I'm programming gui with and without guide. I use handles just to read information from the interface, setappdata/getappdata to:
  1. pass variables to functions in the same or other scripts;
  2. pass functions(f = @function;) to other scripts.
And I use assignin('base') togheter with setappdata(almost all the time) to visualize what is written in setappdata (Just for debbuging, because I don't use evalin('base') to get the value).
Questions:
  1. Is this method a good one? It is working! But is there a faster or better way?
  2. I used setappdata/assignin('base') to more than 70 variables (scalar, Vector or Matrix) and some functions. All that to be shared between 27 scripts. Summary: I can see in workspace all the variables I've assigned in (using assignin('base')), but there are some setappdata which I can not see (because I did not used assignin('base'), for example f=@function ), and I don't remember what is inside, or if they are being used at some point or not. Is there a way to see what is inside all data stored by setappdata (names and values)?
%piece of main script (main.m)
case '0.00001'
step_simulation = 0.00001;
assignin('base', 'step_simulation', step_simulation);
setappdata(hMainGui,'step_simulation', step_simulation);
setappdata(hMainGui,'can do report','no'); %used by other script (report.m)
Victor Morini
Uni. of Sao Paulo - Brazil

Réponses (2)

vcmorini
vcmorini le 24 Mar 2017
Guys, I found a partial answer.
appdata = get(0,'ApplicationData')
or
hMainGui = getappdata(0,'hMainGui')
get(hMainGui)
With that, I can see what is inside the application-defined data.
Also, with the handles command, I can see what is inside the handles struct.
With that, it is possible to clean some trash memory from my gui.
That is it for now.
Now the question is: how to make the gui faster and cleaner. Need best programming practices advices using GUI/GUIDE.
Best!

Adam
Adam le 24 Mar 2017
vals = getappdata(obj);
returns all data stored with a given graphics object.
Personally I attach things to the handles struct in a guide GUI so I can just see them as fields of handles. I never see a need to use things like assignin( 'base' ) though. The debugger works fine for seeing variables in situ and allowing you to step through the code where they are used too, in their correct workspace.
The sharing 70 variables with 27 scripts part sounds like it needs some better organisation of data and algorithms though. It is more difficult without using Matlab OOP, but you can still attach things to structs to pass a lot of parameters to a function (which is far better than a script and works basically the same way but with a sealed workspace).

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by