how to fix this error on gui?
Show older comments
function varargout = WoundAnalysis(varargin)
% WOUNDANALYSIS MATLAB code for WoundAnalysis.fig
% WOUNDANALYSIS, by itself, creates a new WOUNDANALYSIS or raises the existing
% singleton*.
%
% H = WOUNDANALYSIS returns the handle to a new WOUNDANALYSIS or the handle to
% the existing singleton*.
%
% WOUNDANALYSIS('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in WOUNDANALYSIS.M with the given input arguments.
%
% WOUNDANALYSIS('Property','Value',...) creates a new WOUNDANALYSIS or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before WoundAnalysis_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to WoundAnalysis_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help WoundAnalysis
% Last Modified by GUIDE v2.5 02-May-2018 11:44:03
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @WoundAnalysis_OpeningFcn, ...
'gui_OutputFcn', @WoundAnalysis_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before WoundAnalysis is made visible.
function WoundAnalysis_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to WoundAnalysis (see VARARGIN)
% Choose default command line output for WoundAnalysis
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes WoundAnalysis wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = WoundAnalysis_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile('C:\Program Files\MATLAB\R2016a\bin\WOUND IMAGES\.jpg','Select file');
W = [pathname,filename];
axes(handles.axes1)
X = imread(W);
imshow(X);
handles.ImgData = X;
guidata(hObject,handles);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isfield(handles,'ImgData')
XY = handles.ImgData;
s=size(XY);
y=zeros(s(1),s(2));
for i=1 :s(1)
for j=1 :s(2)
if(XY(i,j)>120 && XY(i,j)<215)
y(i,j)=0;
else
y(i,j)=1;
end
end
end
axes(handles.axes2)
imshow(y);
end
handles.ImgData1 = y;
guidata(hObject,handles);
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, ~, ~)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit5_Callback(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit5 as text
% str2double(get(hObject,'String')) returns contents of edit5 as a double
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit6_Callback(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit6 as text
% str2double(get(hObject,'String')) returns contents of edit6 as a double
% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit7_Callback(hObject, eventdata, handles)
% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit7 as text
% str2double(get(hObject,'String')) returns contents of edit7 as a double
% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
J = handles.ImgData1;
meanval = mean2(J);
stdval = std2(J);
%V = skewness(J);
Variance = mean2(var(double(J)));
feat = [meanval, stdval, Variance];
set(handles.edit5,'string',meanval);
set(handles.edit6,'string',stdval);
set(handles.edit7,'string',Variance);
handles.ImgData2 = J;
guidata(hObject,handles);
% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close all
1 Comment
Hana Laili
on 1 Jun 2018
Edited: Walter Roberson
on 1 Jun 2018
Answers (1)
Walter Roberson
on 1 Jun 2018
0 votes
You need to remove or rename your C:\Users\user\Desktop\class.m as it is interfering with the important MATLAB function class()
4 Comments
Shaggy Zee
on 23 May 2020
What's the solution to error like: Reference to non-extistent field 'ImgData' ?
Walter Roberson
on 23 May 2020
pushbutton 8 callback needs to add
if isfield(handles,'ImgData')
Shaggy Zee
on 23 May 2020
Its does not work.
Okay at the end of pushbutton 8 I store the image data into the structure like:
handles.ImageData = image_data;
guidata(hObject, handles);
now at the begining of pushbutton 9 I want to use the image data which is stored in the structure here is my syntex:
j = handles.ImageData;
% This is where the error comes in on the above line . Please if you don't mind we can use any platform to talk one on one.
Walter Roberson
on 23 May 2020
That is not in evidence in your current code. At the moment you have
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
J = handles.ImgData1;
That only works if pushbutton2_Callback has been run. So you need to use
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isfield(handles, 'ImgData1')
J = handles.ImgData1;
stuff
end
At the moment your pushbutton9 only does the "close all". If it needs to access some field, it should protect itself with the same kind of if isfield
A better approach would be to use the Enable properties to enable and disable the pushbuttons. For example, pushbutton1_Callback should have something like
enables = {'pushbutton2', 'edit1', 'edit3', 'edit5', 'edit7', 'pushbutton9'};
disables = {'pushbutton8'};
for F = enables
handles.(F{1}).enable = 'on';
end
for F = disables
handles.(F{1}).enable = 'off';
end
and
function WoundAnalysis_OpeningFcn(hObject, eventdata, handles, varargin)
enables = {'pushbutton1'};
disables = {'pushbutton2', 'edit1', 'edit3', 'edit5', 'edit7', 'pushbutton8', 'pushbutton9'};
for F = enables
handles.(F{1}).enable = 'on';
end
for F = disables
handles.(F{1}).enable = 'off';
end
This way, it is not possible to click on pushbutton8 until pushbutton1 has run and stored ImgData1, so pushbutton8 would not need to check to be sure that imgData1 was present.
Categories
Find more on Graphics Object Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!