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

조회 수: 1 (최근 30일)
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

답변 (2개)

vcmorini
vcmorini 2017년 3월 24일
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 2017년 3월 24일
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).

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by