Display output from neural network on APP Designer
Mostrar comentarios más antiguos
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)
%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
Aditi Mahajan
el 27 de Abr. de 2023
VBBV
el 27 de Abr. de 2023
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
Aditi Mahajan
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
VBBV
el 28 de Abr. de 2023
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)
Aditi Mahajan
el 29 de Abr. de 2023
VBBV
el 29 de Abr. de 2023
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)
Aditi Mahajan
el 29 de Abr. de 2023
Aditi Mahajan
el 29 de Abr. de 2023
VBBV
el 30 de Abr. de 2023
ok, do you still get error ? can you share the code ?
Aditi Mahajan
el 5 de Mayo de 2023
Categorías
Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




