Output from handles instead of globals
Show older comments
I have these three different functions that all relate to the GUI, one doing some stuff, the other one using the result, and the third using the result from the 2nd. I have tried to use globals for the results, but it is a mess, so i was wondering if it was possible to use handles or something like that to do it instead?
function openFile_Callback(hObject, eventdata, handles)
global im;
im = imread(myimage);
-
function analyzeImage_Callback(~, ~, ~)
global im
global dat
level = graythresh(im);
diff_im = im2bw(im,level);
area = sum(diff_im);
dat = [area];
-
function exportResults_Callback(hObject, eventdata, handles)
global dat
csvwrite('csvlist.dat',dat)
Accepted Answer
More Answers (1)
Matt Tearle
on 17 Feb 2011
0 votes
If these functions all live in the same file, the simplest way to pass data around is to use nested functions. A nested function has access to its parent's workspace.
The other way is to use getappdata/setappdata to embed the data in the figure handle.
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!