필터 지우기
필터 지우기

Programatically getting contents from an edit box.

조회 수: 1 (최근 30일)
Jason
Jason 2017년 4월 4일
댓글: Jason 2017년 4월 4일
sorry to raise another thread, I had previously closed with an accepted answer, but this was by mistake. I have tried all suggestions but not getting this to work, even with the handles.figure1 suggestion. To simplify, I programmatically create a checkbox and edit box via:
checkboxCumsum= uicontrol('Style', 'checkbox',...
'String', {'Cum Sum'},...
'Position', [620 0 80 30],...
'Callback', @(src,evt) CumSum( src, evt, ax1,handles.figure1 ));
edx = uicontrol('Style', 'edit',...
'String', {'95'},...
'Position', [700 5 40 20]);
I then create a function Cumsum as:
function CumSum(source,event,ax,handles)
val = source.Value
h=getappdata(0,'histog') %previously drawn histogram
if val==1
hline = findall(gca, 'type', 'line');
delete(hline);
counts=h.Values;
edges=h.BinEdges;
width=h.BinWidth;
ctrs=edges(1:end-1)+width/2;
%integrate histogram using cumsum
cs=cumsum(counts)
l=cs(end)
l1=0.95*l
[ii]=find(cs>l1)
ct=ctrs(ii(1))
hold on
lineH1=plot([ct ct],ylim,'b--','LineWidth',0.7);
text(ct+5,0.90*max(ylim), ['CumSum95=',num2str(ct,'%.0f')],'Fontsize',8,'Color','k','FontWeight','normal')
hold off
x=str2num(get(handles.edx,'String'))
end
I still get the error
No appropriate method, property, or field 'edx' for class 'matlab.ui.Figure'.
  댓글 수: 3
Jason
Jason 2017년 4월 4일
I thought through passing the handles structure?
Jason
Jason 2017년 4월 4일
yes...done it, I have used the Tag property. So in the edit box creation:
edx = uicontrol('Style', 'edit',...
'String', {'95'},...
'Tag','editCumSum',...
'Position', [700 5 40 20]);
And then in the function
hedit = findobj('Tag','editCumSum')
I=cell2mat(hedit.String)

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by