Display output from neural network on APP Designer

4 次查看(过去 30 天)
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

回答(1 个)

VBBV
VBBV 2023-4-27
编辑:VBBV 2023-4-27
%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 个评论
VBBV
VBBV 2023-4-30
ok, do you still get error ? can you share the code ?
Aditi Mahajan
Aditi Mahajan 2023-5-5
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);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Training and Simulation 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by