Programatically (i.e. not using guide) accessing an edit box in another function
이전 댓글 표시
hi. I have create a figure and want to manually create a button and edit box on it too
%Add push button and edit boxes to analyse specific point
f1=figure;
ax1=subplot(1,1,1)
pb1 = uicontrol('Style', 'pushbutton',...
'String', {'Go'},...
'Position', [10 70 80 20],...
'Callback', @(src,evt) IntegratedIntensity( src, evt, ax1,handles ));
edx = uicontrol('Style', 'edit',...
'String', {'x pixel'},...
'Position', [10 40 40 20]);
I have connected the pushbutton to a function:
function IntegratedIntensity(source,event,ax,handles)
x=str2num(get(handles.edx,'String'));
However, when I call this function, the error indicates the edit box isn't recognised.
Reference to non-existent field 'edx'.
댓글 수: 2
Jason
2017년 4월 4일
Adam
2017년 4월 4일
handles.figure1 is a handle to the figure (assuming that is what you have named the field if you are doing it programmatically - it seems to be judging by your error).
If it where in GUIDE you would get the handles structure from this as
handles = guidata( hGUI );
where hGUI would be the 4th argument to your CumSum function, not 'handles' because it is the handle to your GUI figure.
In a programmatic UI though it depends entirely how you have programmed it as to how you need to access things. If you use a nested function then you don't need to pass anything in often. If you do it in a class then the object will usually contain everything you want so is the only needed argument.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 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!