help with gui share data
2 ビュー (過去 30 日間)
古いコメントを表示
i read the link to share data among callbacks, but i still couldnt understand and apply it to my code
in the code and gui, i want to have the drawrectangle function print the position output to 4 editable columns (because i want the user to be able to edit the position with the columns too)
but i can't make the code transferable to other callback functions
can anyone explain to me and also give an example fix to the code?
0 件のコメント
採用された回答
Rik
2020 年 11 月 17 日
For general advice and examples for how to create a GUI (and avoid using GUIDE), have look at this thread.
GUIDE uses guidata, which you can think of as a sort of mat file you store with your figure. You can only save 1 variable, so it makes sense to use a struct, as you can use fieldnames to have some more information in your variable (as opposed to a cell, where it would matter in what order the variables are stored). GUIDE automatically generates the callback functions in such a way that the third input will be the dynamically loaded struct. That means you only need to store back data at the end of your callback function. If you do that, that data will be available to the other callback functions.
5 件のコメント
Rik
2020 年 11 月 18 日
For some reason you insist on sticking with GUIDE. I don't understand why you would want to, but that is your choice.
As the automatically generated documentation of the OpeningFcn already states: you already have the struct with all required data: handles. So your edit was close, except for the fact that you are overwriting the handles struct when you store your variable called data to the figure with guidata.
function v1_gui_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
%either this or handles.data.a and handles.data.a2, pick what makes sense for you
handles.a = 1+1;
handles.a2 = 2+2;
% Update handles structure
guidata(hObject, handles);
You don't need to use data=guidata(hObject); in your callback function as I already explained: the callbacks that are generated by GUIDE already do that.
The main problem with GUIDE is very visible here: you didn't bother reading the comments, because there are too many of them, and most are too complex (or, in the case of eventdata, wrong). You didn't read what the different inputs to your function mean. I would really encourage you to step away from GUIDE. As far as I can tell it has remained mostly unchanged for the last 20 years.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!