Effacer les filtres
Effacer les filtres

Programatically getting contents from an edit box.

1 vue (au cours des 30 derniers jours)
Jason
Jason le 4 Avr 2017
Commenté : Jason le 4 Avr 2017
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 commentaires
Jason
Jason le 4 Avr 2017
I thought through passing the handles structure?
Jason
Jason le 4 Avr 2017
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)

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by