Output from handles instead of globals
古いコメントを表示
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)
採用された回答
その他の回答 (1 件)
Matt Tearle
2011 年 2 月 17 日
0 投票
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.
カテゴリ
ヘルプ センター および File Exchange で Creating, Deleting, and Querying Graphics Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!