Goodnight.
I have the following question. I have 2 .fig files with their respective .m files. In one of the .fig (whose name is -untitled-) create a button to allow me to open the other .fig called -untitled2-. -Untitled2- has a -slider- object that when I move it I want it to redirect the value that it takes to my .fig -untitled-, but the "handles" keeps the button values ​​that allowed me to open the .fig -Untitled2-. I leave codes for further understanding:
Button:
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
openfig('untitled2.fig');
Slide:
function slider1_Callback(hObject, ~, handles)
guidata(hObject,handles);
valor = get(hObject,'value');
set(handles.text2,'String',valor)
handles.data_untitled = valor;
guidata(hObject, handles);
untitled_h = untitled();
The code works for me to send the -slider- data if and only if I do not use the button, that is, directly executing .fig where the -slider- is, but what I want is to be able to open the figure with the button, and then manipulate the -slider- so that it allows me to send the information back to a variable that I have in untitled.m ", which I am not achieving because I suspect that my "handles" is not taking the objects in the figure " untitled2 ".
I leave images for a little more clarity.
I would appreciate your help with this problem. Thank you.

댓글 수: 5

provided that you are using traditional figures
figs = findobj(get(groot, 'children'), 'flat', 'type', 'figure')
otherfig = setdiff(figs, ancestor(hObject, 'figure'))
guidata(otherfig)
Thank you very much for your answer. Partially solve the problem I had with making this code:
function slider1_Callback(hObject, ~, handles)
guidata(hObject,handles);
f = findobj(hObject)
valor = get(f,'value');
handles.data_untitled = valor;
guidata(hObject, handles);
untitled_h = untitled();
Excuse me, I'm not very good at handling handles, but now I have another problem.
In my "untitled2" add 2 objects -edit text- and a button, and a table. I want what I put in the 2 -edit text- to be added to the table after hitting the button, however the handles are as empty array because I am entering "untitled2" from "untitled" (as I mentioned in yesterday's message). In summary of the process that should be carried out in my program: In "untitled" access to "untitled2" by the push button -----> In "untitled2" I modify the -edit text-, press my new button and the data should appear in the table.
The best thing I've managed to achieve is this code for my button, but I can't get the new "handles" of my current figure (untitled2):
function Add_contorno_Callback(hObject, eventdata, handles)
%figs = findobj(get(groot, 'children'), 'flat', 'type', 'figure')
%otherfig = ancestor(hObject, 'figure')
%handles = guidata(otherfig)
%figHandles = findobj('Type', 'figure')
%figHandles = guidata( figHandles(1) )
fig = get (groot, 'CurrentFigure' );
guidata(fig,handles);
f = findobj(fig);
handles = f
Var_X_Cont = str2double(get(handles.X_Contor,'string'));
Var_Y_Cont = str2double(get(handles.Y_Contor,'string'));
I hope you understand each other well.
Thank you.
Pedro - are you still using this code?
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
openfig('untitled2.fig');
I understand what you are trying to do but this is does not open a functioning GUI. From the Limitation section of openfig, ...do not use openfig to open FIG-files created with GUIDE.... While this brings up the figure for the GUI, it does not initialize the GUI components (which is why the handles structure will be empty). When launching a GUIDE GUI from another GUI, just do
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
untitled2;
If you need to save the figure handle of this second GUI in your first GUI, just do
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.otherGui = untitled2;
guidata(hObject, handles);
and then other callbacks in your first GUI would use handles.otherGui when (if) needed.
Pedro Guevara
Pedro Guevara 2020년 5월 22일
Thank you Geoff Hayes.
Works !! I hope
I have no more problems. Could I bother you later with any other questions? I thank you for the explanation.
Geoff Hayes
Geoff Hayes 2020년 5월 22일
Glad it worked out!

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

릴리스

R2017b

질문:

2020년 5월 20일

댓글:

2020년 5월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by