Display output from neural network on APP Designer

I have build a neural network model and saved it to load in APP Designer as shown in figure.
The code is showing no error. But also, it doesn't display the output as required. I have singularly checked each code line's execution in live script and all is working fine. The saved model (MSB.mat) is also being loaded and working fine.
What could be the possibility of no output?
Kindly help!
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: CheckforsuitablematrixButton
function CheckforsuitablematrixButtonPushed(app, event)
% Input variables from the user (Process,Country,FTr,FWf,FAR,TS,TM,FS,FM)
Process=[app.ManufacturingProcessDropDown.Value]
Country=[app.GeographicalLocationDropDown.Value]
FWf=[app.FiberWeightFractionEditField.Value]
FAR=[app.FiberAspectRatioEditField.Value]
TS=[app.TensileStrengthMPaEditField.Value]
TM=[app.TensileModulusGPaEditField.Value]
FS=[app.FlexuralStrengthMPaEditField.Value]
FM=[app.FlexuralModulusGPaEditField.Value]
if strcmp(app.FiberTreatmentDropDown.Value,'Untreated')
FTr=[0];
else
FTr=[1];
end
% Aggregating input variables into a table named IP
IP=table(Process,Country,FTr,FWf,FAR,TS,TM,FS,FM)
% Loading the trained neural network
load MSB.mat
% Predicting the output from the input
Pred_M=predict(MSB,IP)
% Displaying the output
app.UsethegivenMatrixEditField.Value=Pred_M
end
end

Respuestas (1)

VBBV
VBBV el 27 de Abr. de 2023
Editada: VBBV el 27 de Abr. de 2023
%Loading the trained neural network
mdl = load('MSB.mat')
% Predicting the output from the input
Pred_M=predict(mdl,IP.Process)
Check the syntax for using the predict function

12 comentarios

Thanks for your answer.
The code written is right. Its giving output in live script (in figure).
Ok, Since Pred_M seems a categorical variable , use string(Pred_M) to display the output, and also see the following changes to display table data. Hope this helps
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: CheckforsuitablematrixButton
function CheckforsuitablematrixButtonPushed(app, event)
% Input variables from the user (Process,Country,FTr,FWf,FAR,TS,TM,FS,FM)
Process=[app.ManufacturingProcessDropDown.Value]
Country=[app.GeographicalLocationDropDown.Value]
FWf=[app.FiberWeightFractionEditField.Value]
FAR=[app.FiberAspectRatioEditField.Value]
TS=[app.TensileStrengthMPaEditField.Value]
TM=[app.TensileModulusGPaEditField.Value]
FS=[app.FlexuralStrengthMPaEditField.Value]
FM=[app.FlexuralModulusGPaEditField.Value]
if strcmp(app.FiberTreatmentDropDown.Value,'Untreated')
FTr=[0];
else
FTr=[1];
end
% use a UIFigure and UItable to display data in Apps
fig = uifigure
% Aggregating input variables into a table named IP
IP=table(Process,Country,FTr,FWf,FAR,TS,TM,FS,FM,'VariableNames',{'Process','Country','FTr','FWf','FAR','TS','TM','FS','FM'});
UIT = uitable(fig,'Data',IP)
% Loading the trained neural network
load MSB.mat
% Predicting the output from the input
Pred_M=predict(MSB,IP)
% Displaying the output------------------>>> use a string to display
app.UsethegivenMatrixEditField.Value = string(Pred_M)
end
end
The output for the provided code is shown in figure. (uifigure displays the empty figure on pushing the push button)
There is problem with the code lines that are in comments in the following figure as the display of string is working fine.
VBBV
VBBV el 28 de Abr. de 2023
Editada: VBBV el 28 de Abr. de 2023
fig = app.UIFigure
% Aggregating input variables in
IP=table(Process,Country,FTr,FWf,FAR,TS,TM,FS,FM,'VariableNames',{'Process','Country','FTr','FWf','FAR','TS','TM','FS','FM'});
UIT = uitable(fig,'Data',IP)
Use the app.UIFigure instead shown in lines as above
You also need to assign the values to variables in the table as shown below and display using UIFigure in the App
% capture event by user input
Process = event.ManufacturingProcessDropDown.Value;
% assign the value to variable
app.ManufacturingProcessDropDown.Value = Process;
Country = event.GeographicalLocationDropDown.Value
app.GeographicalLocationDropDown.Value = Country;
FWf = event.FiberWeightFractionEditField.Value
app.FiberWeightFractionEditField.Value = Fwf
FAR = event.FiberAspectRatioEditField.Value
app.FiberAspectRatioEditField.Value = FAR
TS = event.TensileStrengthMPaEditField.Value
app.TensileStrengthMPaEditField.Value = TS
TM = event.TensileModulusGPaEditField.Value
app.TensileModulusGPaEditField.Value = TM
FS = event.FlexuralStrengthMPaEditField.Value
app.FlexuralStrengthMPaEditField.Value = FS
FM = event.FlexuralModulusGPaEditField.Value
app.FlexuralModulusGPaEditField.Value = FM
if strcmp(app.FiberTreatmentDropDown.Value,'Untreated')
FTr=[0];
else
FTr=[1];
end
% use a UIFigure and UItable to display data in Apps
fig = app.UIFigure
% Aggregating input variables into a table named IP
IP=table(Process,Country,FTr,FWf,FAR,TS,TM,FS,FM,'VariableNames',{'Process','Country','FTr','FWf','FAR','TS','TM','FS','FM'});
UIT = uitable(fig,'Data',IP)
This is still not working. The code is showing error on the use of
Process=event.ManufacturingProcessDropDown.Value;
Also, there is no output to be displayed in figure.
Can you check now with these following changes
% capture event by user input
Process = event.Value;
% assign the value to variable
app.ManufacturingProcessDropDown.Value = Process;
Country = event.Value
app.GeographicalLocationDropDown.Value = Country;
FWf = event.Value
app.FiberWeightFractionEditField.Value = Fwf
FAR = event.Value
app.FiberAspectRatioEditField.Value = FAR
TS = event.Value
app.TensileStrengthMPaEditField.Value = TS
TM = event.Value
app.TensileModulusGPaEditField.Value = TM
FS = event.Value
app.FlexuralStrengthMPaEditField.Value = FS
FM = event.Value
app.FlexuralModulusGPaEditField.Value = FM
if strcmp(app.FiberTreatmentDropDown.Value,'Untreated')
FTr=[0];
else
FTr=[1];
end
% use a UIFigure and UItable to display data in Apps
fig = app.UIFigure
% Aggregating input variables into a table named IP
IP=table(Process,Country,FTr,FWf,FAR,TS,TM,FS,FM,'VariableNames',{'Process','Country','FTr','FWf','FAR','TS','TM','FS','FM'});
UIT = uitable(fig,'Data',IP)
Still not working
VBBV
VBBV el 29 de Abr. de 2023
Editada: VBBV el 29 de Abr. de 2023
Ok. The ValueChangingFcn callback property needs to be added to all Editboxes GUI component in your App. Then it will work.
I tried. Still not working.
VBBV
VBBV el 30 de Abr. de 2023
ok, do you still get error ? can you share the code ?
properties (Access = private)
Process
Country
FTr
FWf
FAR
TS
TM
FS
FM
IP % Description
end
% Callbacks that handle component events
methods (Access = private)
% Value changed function: ManufacturingProcessDropDown
function ManufacturingProcessDropDownValueChanged(app, event)
app.Process=string(app.ManufacturingProcessDropDown.Value);
end
% Value changed function: FiberWeightFractionEditField
function FiberWeightFractionEditFieldValueChanged(app, event)
value=app.FiberWeightFractionEditField.Value;
% Normalizing
app.FWf=(value-5)/45;
end
% Value changed function: FiberAspectRatioEditField
function FiberAspectRatioEditFieldValueChanged(app, event)
value=app.FiberAspectRatioEditField.Value;
% Normalizing
app.FAR=(value-3.15)/996.85;
end
% Value changed function: FiberTreatmentDropDown
function FiberTreatmentDropDownValueChanged(app, event)
if strcmp(app.FiberTreatmentDropDown.Value,'Untreated')
app.FTr=0;
else
app.FTr=1;
end
end
% Value changed function: GeographicalLocationDropDown
function GeographicalLocationDropDownValueChanged(app, event)
app.Country=app.GeographicalLocationDropDown.Value;
end
% Value changed function: TensileStrengthMPaEditField
function TensileStrengthMPaEditFieldValueChanged(app, event)
value=app.TensileStrengthMPaEditField.Value;
% Normalizing
app.TS=(value-1.62)/49.753;
end
% Value changed function: FlexuralStrengthMPaEditField
function FlexuralStrengthMPaEditFieldValueChanged(app, event)
value=app.FlexuralStrengthMPaEditField.Value;
% Normalizing
app.FS=(value-2.06)/104.34;
end
% Value changed function: TensileModulusGPaEditField
function TensileModulusGPaEditFieldValueChanged(app, event)
value=app.TensileModulusGPaEditField.Value;
% Normalizing
app.TM=(value-0.0834)/4.0006;
end
% Value changed function: FlexuralModulusGPaEditField
function FlexuralModulusGPaEditFieldValueChanged(app, event)
value=app.FlexuralModulusGPaEditField.Value;
% Normalizing
app.FM=(value-0.187)/4.913
end
% Button pushed function: CheckforsuitablematrixButton
function CheckforsuitablematrixButtonPushed(app, event)
% Loading classification neural network
net=load('MSB.mat');
% Aggregating input variables into a table named IP
app.IP=table('Size',[1 9], ...
'VariableTypes',{'categorical','categorical','double','double','double','double','double','double','double'}, ...
'VariableNames',net.MSB.PredictorNames);
app.IP.Process(1)=categorical(app.Process);
app.IP.Country(1)=categorical(app.Country);
app.IP.FTr(1)=app.FTr;
app.IP.FWf(1)=app.FWf;
app.IP.FAR(1)=app.FAR;
app.IP.TS(1)=app.TS;
app.IP.TM(1)=app.TM;
app.IP.FS(1)=app.FS;
app.IP.FM(1)=app.FM;
% Predicting the output from the input
Pred_M=predict(net.MSB,app.IP);
% Displaying the output
app.UsethegivenMatrixEditField.Value=char(Pred_M);

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Productos

Versión

R2022a

Preguntada:

el 27 de Abr. de 2023

Comentada:

el 5 de Mayo de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by