I was working on Matlab R2015a's Classification Learner Toolbox. I successfully imported the file data and export it using Export Model, and i got a structure named trainedClassifier. But while running its showing the following error

2 次查看(过去 30 天)
matlab code clc; clear all; close all; a= readtable('input.csv'); height = [167; 152; 150; 159; 275; 285; 200; 253]; T =height; yfit = predict(trainedClassifier, T{:,trainedClassifier.PredictorNames})
error Undefined function or variable 'trainedClassifier'.
Error in check (line 7) yfit = predict(trainedClassifier, T{:,trainedClassifier.PredictorNames})
  1 个评论
Ceethal Kottakali Piyus
Someone, please help me...I'm working on an EEG classifier based project for that this Classification Learner Toolbox will be a great help, but I got stuck in the very beginning...

请先登录,再进行评论。

采纳的回答

Sean de Wolski
Sean de Wolski 2017-10-24
trainedClassifier is not in your workspace because you have a clear all at the beginning of the script which is clearing it.
I would recommend saving it after exporting and then loading in the script
Export from app.
save trainedClassifier.mat trainedClassifier
In script
load trainedClassifier.mat
predict(etc...)

更多回答(1 个)

Roya Salehzadeh
Roya Salehzadeh 2022-11-7
Hi,
I have trained a classifier in MATLAB 2022 and saved it. I need to load the trained classifier inside a matlab function in Simulink (non in an m.file ) in MATLAB 2015a, and then use predict() fucntion. . Do you have any idea on how I should do that?
These commands work fine for the MATLAB 2022, when I use them inside the matlab function of Simulink block but they are not available for MATLAB 2015a:
  • saveLearnerForCoder()
  • loadLearnerForCoder()
For MATLAb 2015a, I tried to save the classifier in MATLAB 2022a as a mat file and then load the matin MATLAB 205a file and use predict function. It works when use these commands in command window or m.file, but When I use these inside the simulink matlab function I recieve an error.
function label = svmIonospherePredict(XTest) %#codegen
load('MdlLinear.mat'); %%% this loads an object
[label] = predict(MdlLinear,XTest);
end
  • The output of a call to 'load' is not assigned to a variable. Assign its output to a variable without subscripting.
  • Undefined function or variable 'MdlLinear'.

类别

Help CenterFile Exchange 中查找有关 Classification Learner App 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by