MATLAB Answers


"uicontrol" is not working well in MATLAB2015b

Meshooo 님이 질문을 제출함. 2 Feb 2016
최근 활동 Meshooo 님이 댓글을 추가함. 8 Feb 2016
Dear all, I couldn't run this code in MATLAB2015b, but it was working well before
uicontrol('Style', 'pushbutton', 'String', 'SAVE',...
'Position', [20 20 50 20],...
'Callback', ...
@yourCallback); % what do you want to do?
function yourCallback(ObjH, EventData)
I = getimage;
setappdata(0, 'I', I);
resXGui; %the name of the GUI where to transfer
Error:Function with duplicate name "yourCallback" cannot be defined.
Does anyone knows how to make it work again for MATLAB2015b?
Regards, Meshoo

  댓글 수: 0

로그인 to comment.

답변 수: 1

Answer by Jan
on 2 Feb 2016
Edited by Jan
on 2 Feb 2016

There is another function called "yourCallback" inside the M-file. Rename the function - I suggest to use meaningful names, because this reduces the chance for such collisions.

  댓글 수: 4

표시 이전 댓글 수: 1
Let's say we have two GUIs, A_GUI and B_GUI and both have axes. Let's say we opened an image in a separate figure
I = imread('cameraman.tif');
figure, imshow (I);
Now how to attach a button to this figure, such that by clicking the button the image I will open in B_GUI.
Provided that B_GUI is the figure handle of the target figure (or a uipanel or uitab on the target figure)
I = imread('cameraman.tif');
newfig = figure();
newax = axes('Parent', newfig);
Ih = imshow(newax, I);
cb = @(hObject, eventdata) imshow(axes('Parent', B_GUI), get(Ih, 'CData'))
bh = uicontrol('style', 'push', 'Parent', newfig, 'Callback', cb);
OK, thank you very much.

로그인 to comment.

Translated by