Understanding and using guihandles programmatically
8 ビュー (過去 30 日間)
古いコメントを表示
Hi
I am programmatically creating a GUI interface with a number of plots that connects to an outside function in the callback. The outside function creates new values for the plots and I want to be able to update the plots from that function (the part of the function that updates the plots is run in a timer). I am confused by guidata and guihandles and how to approach this. In another program I tried just passing in the axes handle and that didn't work anyway. This time I have multiple axes to update so I'd prefer to pass them all in in one object if I can.
I created a figure and the myHandles reference, and I can see when I add tags to my uicontrols that they are stored in myHandles. I presume I pass myHandles to my outside function, but I'm not sure how to update them from that function so the graph is updated.
f = figure;
myhandles = guihandles(f);
Thanks
0 件のコメント
採用された回答
Jan
2016 年 5 月 7 日
function CreateFigure
handles.FigH = figure('Tag', 'myFigure';
handles.axes1 = subplot(2,2,1);
handles.axes2 = subplot(2,2,2);
handles.axes3 = subplot(2,2,3);
handles.axes4 = subplot(2,2,4);
handles.Button = uicontrol('Style', 'PushButton', ...
'Callback' {@myCallback, handles.FigH});
... % And the other uicontrols
guidata(FigH, handles); % Store handles struct in the figure
Now it depends how you call the "external function". If they are called from buttons or menus inside the figure, provide the figure handle as shown for the button's callback:
function myCallback(ButtonH, EventData, FigH)
externalFunction(FigH)
Then you can get the handles in the external function:
function externalFunction(FigH)
handles = guidata(FigH);
plot(1:10, rand(1, 10), 'Parent', handles.axes1);
But then the calculations and the GUI are mixed. Prefer to leave the GUI parts and the calculations separated:
function myCallback(ButtonH, EventData, FigH)
Data = externalFunction;
handles = guidata(FigH);
plot(Data.x, Data.y, 'Parent', handles.axes1);
And the clean external function:
function Data = externalFunction()
Data.x = 1:10;
Data.y = rand(1, 10);
0 件のコメント
その他の回答 (1 件)
参考
カテゴリ
Help Center および 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!