Set default value textedit

1 次查看(过去 30 天)
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 个评论
MARIA RODRIGUEZ SANZ
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
I don't know what do you mean with initialize the field... Sorry

请先登录,再进行评论。

采纳的回答

Rik
Rik 2018-7-23
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 个评论
MARIA RODRIGUEZ SANZ
Thank you. That worked perfect! So simply! No if statements were necessary...

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by