How to solve "Reference to non-existent field 'net'" on app designer?

1 view (last 30 days)
I'm trying to make a deep-learning app which classifies with my neural network.
but I always get this "Reference to non-existent field 'net'" message. How can I solve it?
classdef ImageHistogramsAppExample < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
ImageAxes matlab.ui.control.UIAxes
LoadButton matlab.ui.control.Button
TextAreaLabel matlab.ui.control.Label
TextArea matlab.ui.control.TextArea
Button matlab.ui.control.Button
end
properties (Access = public)
end
properties (Access = private)
leafnet;
leafnet2;
leafnet3;
end
methods (Access = private)
function updateimage(app,imagefile)
try
ima12 = imread(imagefile);
im=imresize(ima12,[227 227]);
imwrite(im,sprintf('testimage.jpg'));
catch ME
% If problem reading image, display error message
uialert(app.UIFigure, ME.message, 'Image Error');
return;
end
% Create histograms based on number of color channels
switch size(im,3)
case 1
% Display the grayscale image
imagesc(app.ImageAxes,im);
case 3
% Display the truecolor image
imagesc(app.ImageAxes,im);
otherwise
% Error when image is not grayscale or truecolor
uialert(app.UIFigure, 'Image must be grayscale or truecolor.', 'Image Error');
return;
end
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
% Configure image axes
app.ImageAxes.Visible = 'on';
app.ImageAxes.Colormap = gray(256);
axis(app.ImageAxes, 'image');
app.leafnet=load("leafnet.mat");
app.leafnet=SeriesNetwork.loadobj(app.leafnet.net);
app.leafnet2=load("leafnet2.mat");
app.leafnet2=SeriesNetwork.loadobj(app.leafnet2.net);
app.leafnet3=load("leafnet3.mat");
app.leafnet3=SeriesNetwork.loadobj(app.leafnet3.net);
end
% Value changed function: TextArea
function DropDownValueChanged(app, event)
% Update the image and histograms
updateimage(app, app.DropDown.Value);
end
% Button pushed function: LoadButton
function LoadButtonPushed(app, event)
% Display uigetfile dialog
filterspec = {'*.jpg;*.tif;*.png;*.gif','All Image Files'};
[f, p] = uigetfile(filterspec);
% Make sure user didn't cancel uigetfile dialog
if (ischar(p))
fname = [p f];
updateimage(app, fname);
end
end
% Button pushed function: Button
function ButtonPushed(app, event)
testds=imageDatastore("testimage.jpg");
test1=classify(app.leafnet,testds);
test2=classify(app.leafnet2,testds);
test3=classify(app.leafnet3,testds);
if test1=="basic"
result1='1a';
elseif test1=="noleaf"
result1='1b';
end
if test2=="basic"
result2='2a';
elseif test2=="fruit"
result2='2b';
end
if test3=="basic"
result3='3a';
elseif test3=="left"
result3='3b';
elseif test3=="right"
result3='3c';
end
if result1=="1a"
if result2=="2a"
if result3=="3a"
disp("잎이 무성한 일반 나무를 중앙에 그리셨군요. 당신은 심리적으로 안정된 상태일 가능성이 높습니다. 적정한 수준의 자기애와 큰 걱정거리가 없는 심리상태로 보여집니다.")
elseif result3=="3b"
disp("잎이 무성한 일반 나무를 왼쪽에 치우치게 그리셨군요. 당신은 과거에 고착되어 미래에 대한 불안감에 휩싸여 있을 가능성이 높습니다. 과거에 대한 집착을 버리고 낙관적 미래를 기대해 보는 것은 어떨까요?")
elseif result3=="3c"
disp("잎이 무성한 일반 나무를 오른쪽에 치우치게 그리셨군요. 당신은 충동적 정서에 대한 두려움에서 기이한 성격적 불균형을 가지고 있는 것으로 보이며 불유쾌한 기억을 억압하려는 욕구가 있을 것으로 보여집니다. 두려움과 불쾌한 감정에 대한 거부감을 낮출 필요성이 보입니다.")
end
elseif result2=="2b"
if result3=="3a"
disp("잎이 무성한 사과나무를 그리셨군요. 당신이 성인이라면 미성숙/퇴행 등을 겪고 있을 가능성이 있으며 아동이라면 의존욕구/애정욕구가 강한 것으로 보여집니다. 좀더 마음을 단단히 먹고 성숙한 정신상태를 유지할 필요가 있어 보입니다.")
elseif result3=="3b"
disp("잎이 무성한 사과나무를 왼쪽에 치우치게 그리셨군요. 당신이 성인이라면 미성숙/퇴행 등을 겪고 있을 가능성이 있으며 아동이라면 의존욕구/애정욕구가 강한 것으로 보여집니다. 또한 당신은 과거에 고착되어 미래에 대한 불안감에 휩싸여 있을 가능성이 높습니다. 과거에 대한 집착은 버리고 낙관적 미래를 성숙한 마음가짐으로 바라보는 것이 필요해 보입니다.")
elseif result3=="3c"
disp("잎이 무성한 사과나무를 오른쪽에 치우치게 그리셨군요. 당신이 성인이라면 미성숙/퇴행 등을 겪고 있을 가능성이 있으며 아동이라면 의존욕구/애정욕구가 강한 것으로 보여집니다. 또한 충동적 정서에 대한 두려움에서 기이한 성격적 불균형을 가지고 있는 것으로 보이며 불유쾌한 기억을 억압하려는 욕구가 있어 보입니다. 성숙한 자세로 두려움과 불쾌한 감정에 의연해질 필요성이 있어 보입니다.")
end
end
elseif result1=="1b"
if result2=="2a"
if result3=="3a"
disp("잎과 열매가 없는 죽은 나무를 그리셨군요. 당신은 지금 내적 황폐/자아통합의 어려움을 겪는 위험한 상태일수 있습니다. 빨리 가까운 병원 혹은 심리상담소를 찾아가세요.")
elseif result3=="3b"
disp("잎과 열매가 없는 죽은 나무를 오른쪽으로 치우치게 그리셨군요. 당신은 지금 내적 황폐/자아통합의 어려움을 겪는 위험한 상태일 수 있습니다. 또한 충동적 정서에 대한 두려움이 기이한 성격적 불균형 등을 겪는 상태 일 수 있습니다. 빨리 가까운 병원 혹은 심리상담소를 찾아가세요.")
elseif result3=="3c"
disp("잎과 열매가 없는 죽은 나무를 왼쪽으로 치우치게 그리셨군요. 당신은 지금 내적 황폐/자아통합의 어려움을 겪는 위험한 상태일 수 있습니다. 또한 과거에 고착되어 있거나 미래에 불안을 느끼고 있을 가능성이 높습니다. 빨리 가까운 병원 혹은 심리상담소를 찾아가세요.")
end
elseif result2=="2b"
if result3=="3a"
disp("잎이 없는 죽은나무에 열매만 열려있군요. 당신은 지금 내적 황폐/자아통합의 어려움을 겪는 위험한 상태일 수 있습니다. 또한 미성숙과 퇴행 혹은 애정결핍 상태일 수 있습니다. 빨리 가까운 병원 혹은 심리상담소를 찾아가세요.")
elseif result3=="3b"
disp("잎이 없고 열매만 달려있는 나무를 왼쪽에 치우치게 그리셨군요. 당신은 지금 내적 황폐/자아통합의 어려움을 겪는 위험한 상태일 수 있습니다. 또한 미성숙과 퇴행 혹은 애정결핍 상태일 수 있으며 불유쾌한 기억을 억압하려 하고 있고 과거에 고착되어 미래에 대한 불안을 느끼고 있을 가능성이 높습니다. 빨리 가까운 병원 혹은 심리상담소를 찾아가세요.")
elseif result3=="3c"
disp("잎이 없고 열매만 달려있는 나무를 오른쪽에 치우치게 그리셨군요. 당신은 지금 내적 황폐/자아통합의 어려움을 겪는 위험한 상태일 수 있습니다. 또한 미성숙과 퇴행 혹은 애정결핍 상태일 수 있으며 불유쾌한 기억을 억압하려 하고 있고 두려움에 기인한 성격적 불균형을 가지고 있을수 있습니다. 빨리 가까운 병원 혹은 심리상담소를 찾아가세요.")
end
end
end
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.AutoResizeChildren = 'off';
app.UIFigure.Position = [100 100 702 528];
app.UIFigure.Name = 'Image Histograms';
app.UIFigure.Resize = 'off';
% Create ImageAxes
app.ImageAxes = uiaxes(app.UIFigure);
app.ImageAxes.XTick = [];
app.ImageAxes.XTickLabel = {'[ ]'};
app.ImageAxes.YTick = [];
app.ImageAxes.Position = [43 181 357 305];
% Create LoadButton
app.LoadButton = uibutton(app.UIFigure, 'push');
app.LoadButton.ButtonPushedFcn = createCallbackFcn(app, @LoadButtonPushed, true);
app.LoadButton.Position = [442 322 225 22];
app.LoadButton.Text = 'Load Custom Image';
% Create TextAreaLabel
app.TextAreaLabel = uilabel(app.UIFigure);
app.TextAreaLabel.HorizontalAlignment = 'right';
app.TextAreaLabel.Position = [43 101 56 22];
app.TextAreaLabel.Text = 'Text Area';
% Create TextArea
app.TextArea = uitextarea(app.UIFigure);
app.TextArea.ValueChangedFcn = createCallbackFcn(app, @DropDownValueChanged, true);
app.TextArea.Position = [114 65 553 60];
% Create Button
app.Button = uibutton(app.UIFigure, 'push');
app.Button.ButtonPushedFcn = createCallbackFcn(app, @ButtonPushed, true);
app.Button.Position = [505 232 100 22];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = ImageHistogramsAppExample
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end

Answers (1)

Benjamin Kraus
Benjamin Kraus on 5 Jan 2021
You did not indicate what line of code the error message is coming from, but I'm guessing the error is coming from one of these lines:
app.leafnet=load("leafnet.mat");
app.leafnet=SeriesNetwork.loadobj(app.leafnet.net);
app.leafnet2=load("leafnet2.mat");
app.leafnet2=SeriesNetwork.loadobj(app.leafnet2.net);
app.leafnet3=load("leafnet3.mat");
app.leafnet3=SeriesNetwork.loadobj(app.leafnet3.net);
It is impossible to definitively answer your question without knowing what is in your .mat files, but the error message suggests that you have no variables named net stored in any of your .mat files.
In order for someone to help you further, you should indicate how you created those files.

Categories

Find more on Develop uifigure-Based Apps 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!