Guide toolbar toggle button within another function
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi All,
I have created a GUI using guide and added a toggle button to the toolbar. I am trying to use this toggle button within another function to turn something on and off. My problem is I do not know how to properly call the handle and use it within the if statement. The code is listed below.
Details: There is an axes within the GUI that the user can draw points on. As the points are drawn they are numbered. I want to create a toggle button that allows the user to turn the numbering either on or off.
function createNode(x, y, hObject, handles)
nextN = size(handles.nodes,1)+1;
temp = plot(x, y, handles.pointStyle);
set(temp, 'HitTest', 'off');
label = yieldLabelText(nextN, handles.options.labeling);
temptext = text(double(x), double(y), ' ', 'VerticalAlignment','bottom', 'HorizontalAlignment','right');
set(temptext, 'HitTest', 'off', 'String',label,'FontSize',12,'Visible','on');
%Node number labels
%NOT SURE HOW TO SET THIS UP CORRECTLY*
if strcmp(get(handles.uitoggletool1,'Checked'),'on')
%Node number labels
set(temptext, 'HitTest', 'off', 'String',label,'Visible','off') ;
else
%Node number labels
set(temptext, 'HitTest', 'off', 'String',label,'FontSize',12);
end
댓글 수: 2
Jan
2014년 11월 16일
편집: Jan
2014년 11월 16일
The description of what you want to achieve is not clear:
I am trying to use this toggle button within another function to turn something on and off.
Please explain this with more details. To know, how this can be programmed correctly, we have to know, what you want it to do and when this should happen.
Please add this information by editing the original question, not by hidding this important information inside a comment. Thanks.
채택된 답변
Geoff Hayes
2014년 11월 16일
Christopher - use the Value property of the toggle button to determine if the toggle has been pressed or not. Try the following
if get(handles.uitoggletool1,'Value')==1
%Node number labels
set(temptext, 'HitTest', 'off', 'String',label,'Visible','off') ;
else
%Node number labels
set(temptext, 'HitTest', 'off', 'String',label,'FontSize',12);
end
If the Value property is one, then the toggle has been pressed. Though, from the above code, it isn't clear why you would create a text object just to hide it by setting its Visible property to off. Will you be keeping track of this handle, temptext, so that you can make it visible if the toggle is not pressed?
I think that much of the code to create the text control and set its properties can be reduced to
if get(handles.uitoggletool1,'Value')==1
visibleProp = 'off';
else
visibleProp = 'on';
end
temptext = text(double(x), double(y), ' ', 'VerticalAlignment','bottom', ...
'HorizontalAlignment', 'right', 'HitTest', 'off', ...
'String',label, 'FontSize',12, 'Visible', visibleProp);
Give the above a go and see what happens!
댓글 수: 10
Geoff Hayes
2014년 11월 17일
Glad it worked out, Christopher! As for resources, I use this forum or the File Exchange for ideas on how to program more complicated GUIs.
추가 답변 (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!