Set default value textedit

1 view (last 30 days)
MARIA RODRIGUEZ SANZ
MARIA RODRIGUEZ SANZ on 23 Jul 2018
Hello,
I am new in GUI. I have created some GUI script in order to process images that contains the following syntax:
function Num_seg_Callback(hObject, eventdata, handles)
numseg=str2double(get(hObject,'String'));
if isempty(numseg) %I have also tried isnan
numseg=1;
end
handles.numseg=numseg;
guidata(hObject,handles);
I would like to set 1 as the default value of a text edit object (numseg) which I use below in my code. This syntax is giving an error (Reference to non-existent field 'numseg') and it works only if I first write a number and then delete it. Does anyone have an idea of why is this occurring? Why it doesn't work the first time I run it?
I have also tried: if isnan(numseg) set (handles.numseg,'String',1); end ...
  3 Comments
MARIA RODRIGUEZ SANZ
MARIA RODRIGUEZ SANZ on 23 Jul 2018
I Rik
Thanks for your response,
I think that it triggers the error when I try to call numseg in this code below:
%====================================================================================
% BOTON SEGMENTACION
%====================================================================================
% --- Executes on button press in Boton_segmentar.
function Boton_segmentar_Callback(hObject, eventdata, handles)
% hObject handle to Boton_segmentar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%SI EXISTE LA IMAGEN CORTADA, LA SEGMENTAS Y SI NO HA CORTADO NADA LO HACES
%CON LA CRUDA:
%------------------------------------------------------------------------------
% PREPROCESAMOS LA IMAGEN PARA SEGMENTAR
%------------------------------------------------------------------------------
Imagengs=rgb2gray(Imagen_segmentar);
histeq=adapthisteq(Imagengs); %Ecualizacion del histograma
ajus = imadjust(histeq,[0.3 0.7],[0 1]); %Ajustamos contraste
edges= edge(ajus,'Canny'); %Calculamos los bordes
fil=imdilate(edges,ones(7,7)); %Dilatamos los puntos
fil=imcomplement(fil); %Creamos la complementaria
%-----------------------------------------------------------------------------
% SEGMENTACION
%-----------------------------------------------------------------------------
lab=bwlabel(fil); %Marcamos las etiquetas de las regiones
BW2 = bwareafilt(fil,handles.numseg); %Eliminamos todos los segmentos que no sean del strip
BW2_fill=imfill(BW2,'holes'); %Rellenamos los huecos que puedan quedar en medio del strip
strip=bwlabel(BW2_fill); %Volvemos a guardar las etiquetas de los nuevos segmentos
%-------------------------------------------------------------------
%MOSTRAMOS EL RESULTADO DE LA SEGMENTACION
%--------------------------------------------------------------------
axes(handles.plot1) %Le indicamos que estamos trabajando en el plot1
cla %Borra la imagen anterior que haya en el current axes
overlay2 = imOverlay(Imagen_segmentar, BW2_fill, [.3 1 .3]);
imshow(overlay2); %Muestra la imagen segmentada
MARIA RODRIGUEZ SANZ
MARIA RODRIGUEZ SANZ on 23 Jul 2018
I don't know what do you mean with initialize the field... Sorry

Sign in to comment.

Accepted Answer

Rik
Rik on 23 Jul 2018
In your OpeningFcn, you need to set a value for the numseg field. That way, the field exists in your handles struct and that other function can use it.
  1 Comment
MARIA RODRIGUEZ SANZ
MARIA RODRIGUEZ SANZ on 23 Jul 2018
Thank you. That worked perfect! So simply! No if statements were necessary...

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!