Sim() error in MATLAB app designer

3 views (last 30 days)
Farhan Baig
Farhan Baig on 8 Nov 2022
Answered: Steven Lord on 9 Nov 2022
I'm having an error while creating an app on app designer. The net.mat file was loaded into var and was accessed in y=sim(app.var,p). as shown:
classdef FAM < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
DiabeticRetinopathyDetectionLabel matlab.ui.control.Label
DevelopedbyFarhanHamzaLabel matlab.ui.control.Label
LoadimageButton matlab.ui.control.Button
UIAxes matlab.ui.control.UIAxes
UIAxes2 matlab.ui.control.UIAxes
UIAxes3 matlab.ui.control.UIAxes
VesselsButton matlab.ui.control.Button
ExudatesButton matlab.ui.control.Button
end
properties (Access = public)
var = load('F:\Study\BME BOOKS\Semester 7\imaging\project2\Diabetic-Retinopathy-Detection-master\net.mat'); % specify the path to mat file
end
methods (Access = private)
% Button pushed function: LoadimageButton
function loadimage(app, event)
global data;
[FileName,PathName] = uigetfile('*.png;','select the image'); %reading the specifies types of the image
dat=imread([PathName,FileName]);
data=imresize(dat,[500 700]); %reesizing the image into 500 700
imshow(data,'Parent',app.UIAxes);
end
% Button pushed function: VesselsButton
function VesselsButtonPushed(app, event)
global data;
global bw2;
global c;
global mea2;
global sd1;
global numberOfCircles;
greenchannel = data(:,:,2); % green channel of the image
ginverse = imcomplement (greenchannel); % complementing green channel
adahisteq = adapthisteq(ginverse); %increasing the intensity of the inverse green channel for highlitening the blood vessel
threshold = 0.2;
BW = edge(adahisteq,'Canny',threshold); %canny detection
h=imfill(BW,'holes'); % filling the holes
k=h-BW;
BW2 = bwpropfilt(logical(k),'Area',[7 12]); %taking out the clustered pixels of the specified range area
[l,numberOfCircles]= bwlabel(BW2); % counting the number of clustered pixels
%extraction of blood vessel and haemorrhages
greenc = data(:,:,2); % Extract Green Channel
ginv = imcomplement (greenc); % Complement the Green Channel
adahist = adapthisteq(ginv);
se = strel('ball',8,8); % Structuring Element
gopen = imopen(adahist,se); % Morphological Open
godisk = adahist - gopen; % Remove Optic Disk
medfilt = medfilt2(godisk); %2D Median Filter
background = imopen(medfilt,strel('disk',15));% imopen function
I2 = medfilt - background; % Remove Background
I3 = imadjust(I2); % Image Adjustment
level = graythresh(I3); % Gray Threshold
bw = im2bw(I3,level); % Binarization
bw1 = bwareaopen(bw, 30);
[i,j]= size(bw1);
c=0;
for i=1:500
for j=1:700
if bw1(i,j)==1
c=c+1;
end
end
end
imshow(bw1,'Parent',app.UIAxes2);
bw2=im2bw(bw1); %#ok<*IM2BW>
mea2=mean2(bw2);
sd1=std2(bw2);
end
% Button pushed function: ExudatesButton
function ExudatesButtonPushed(app, event)
global data;
global mea2;
global sd1;
global c;
global numberOfCircles;
%global net;
g=data(:,:,2);
a=adapthisteq(g);
im= imadjust(a);
im2=im2bw(im,.9);
med=medfilt2(im2);
im3=imerode(med,strel('disk',10));
im4=imdilate(im3,strel('octagon',63));
im5=imimposemin(g,im4);
im6=g-im5;
im8=adapthisteq(im6);
im9=im2bw(im8);
med1=medfilt2(im9);
im10=imdilate(med1,strel('disk',40));
im12=med-im10;
im13=im2bw(im12);
BW2 = bwpropfilt(logical(im13),'Area',[0 1000]);
[k,l]= size(BW2);
c1=0;
for k=1:500
for l=1:700
if im12(k,l)==1
c1=c1+1;
end
end
end
imshow(BW2,'Parent',app.UIAxes3);
mea1=mean2(BW2);
sd2=std2(BW2);
p=[c;c1;numberOfCircles;mea2;sd1;mea1;sd2]; % seven iput features
y=sim('app.var',p); %estimted
o=round(y);
a1=[0 0 0 1]; % target values of the class 1
a2=[0 0 1 0]; % target values of the class 2
a3=[0 1 0 0]; % target values of the class 3
a4=[1 0 0 0]; % target values of the class 4
a11=a1.';
a22=a2.'; %Transpose
a33=a3.';
a44=a4.';
if o == a11
%disp('Normal eye');
fig1 = uifigure;
message1 = {'Normal eye'};
uialert(fig1,message1,'Sucess',...
'Icon','Success');
else if o== a22
%disp('Mild nonproliferative retinopathy');
fig2 = uifigure;
message2 = {'Mild nonproliferative retinopathy'};
uialert(fig2,message2,'Sucess',...
'Icon','Success');
else if o==a33
% disp('moderate nonproliferative retinopathy');
fig3 = uifigure;
message3 = {'moderate nonproliferative retinopathy'};
uialert(fig3,message3,'Sucess',...
'Icon','Success');
else
% disp('severe npdr');
fig4 = uifigure;
message4 = {'severe npdr'};
uialert(fig4,message4,'Sucess',...
'Icon','Success');
end
end
end
end
end
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure
app.UIFigure = uifigure;
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
% Create DiabeticRetinopathyDetectionLabel
app.DiabeticRetinopathyDetectionLabel = uilabel(app.UIFigure);
app.DiabeticRetinopathyDetectionLabel.HorizontalAlignment = 'center';
app.DiabeticRetinopathyDetectionLabel.FontSize = 20;
app.DiabeticRetinopathyDetectionLabel.FontWeight = 'bold';
app.DiabeticRetinopathyDetectionLabel.Position = [168 425 305 34];
app.DiabeticRetinopathyDetectionLabel.Text = 'Diabetic Retinopathy Detection';
% Create DevelopedbyFarhanHamzaLabel
app.DevelopedbyFarhanHamzaLabel = uilabel(app.UIFigure);
app.DevelopedbyFarhanHamzaLabel.HorizontalAlignment = 'center';
app.DevelopedbyFarhanHamzaLabel.FontWeight = 'bold';
app.DevelopedbyFarhanHamzaLabel.Position = [230 404 181 22];
app.DevelopedbyFarhanHamzaLabel.Text = 'Developed by Farhan & Hamza';
% Create LoadimageButton
app.LoadimageButton = uibutton(app.UIFigure, 'push');
app.LoadimageButton.ButtonPushedFcn = createCallbackFcn(app, @loadimage, true);
app.LoadimageButton.BackgroundColor = [0.302 0.749 0.9294];
app.LoadimageButton.FontWeight = 'bold';
app.LoadimageButton.Position = [55 372 100 22];
app.LoadimageButton.Text = 'Load image';
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Orignal image')
app.UIAxes.Position = [198 203 301 191];
% Create UIAxes2
app.UIAxes2 = uiaxes(app.UIFigure);
title(app.UIAxes2, 'Vessels and Microaneuryms')
app.UIAxes2.Position = [15 13 286 191];
% Create UIAxes3
app.UIAxes3 = uiaxes(app.UIFigure);
title(app.UIAxes3, 'Exudates')
app.UIAxes3.Position = [326 19 300 185];
% Create VesselsButton
app.VesselsButton = uibutton(app.UIFigure, 'push');
app.VesselsButton.ButtonPushedFcn = createCallbackFcn(app, @VesselsButtonPushed, true);
app.VesselsButton.Position = [55 319 100 22];
app.VesselsButton.Text = 'Vessels';
% Create ExudatesButton
app.ExudatesButton = uibutton(app.UIFigure, 'push');
app.ExudatesButton.ButtonPushedFcn = createCallbackFcn(app, @ExudatesButtonPushed, true);
app.ExudatesButton.Position = [55 264 100 22];
app.ExudatesButton.Text = 'Exudates';
end
end
methods (Access = public)
% Construct app
function app = FAM
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
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
But I'm having this error:

Answers (2)

Kojiro Saito
Kojiro Saito on 9 Nov 2022
You need to input app.var without single quotations.
If you have saved your trained model (variable net),
save('net.mat', "net")
a
y=sim('app.var',p); %estimted
should be
y = sim(app.var.net, p); %estimted

Steven Lord
Steven Lord on 9 Nov 2022
y=sim('app.var',p); %estimted
This tries to call a version of the sim function that accepts a char vector as the first input. That's not what I believe you want. Determine the variable in the MAT-file that contains the object you want to simulate (I'll assume it's called theNet) and index into that variable stored in the property of your app.
y = sim(app.var.theNet, p);

Categories

Find more on Develop Apps Using App Designer 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!