GUI issues -> 1) memory: assignin, getappdata/setappdata and handles 2) best programming practices
Show older comments
Hi,
I'm programming gui with and without guide. I use handles just to read information from the interface, setappdata/getappdata to:
- pass variables to functions in the same or other scripts;
- 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:
- Is this method a good one? It is working! But is there a faster or better way?
- 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
Answers (2)
vcmorini
on 24 Mar 2017
Adam
on 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).
Categories
Find more on Structures 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!