Reference to non-existent field 'predictFcn'.

3 views (last 30 days)
Yogi Jefani
Yogi Jefani on 2 Aug 2017
Edited: Jahnavi Samal on 25 Jan 2023
I'm going to predict a new data using a SVM classification model which I created using the classification learner apps. After I export the model into workspace, I save the model into .mat file using command
save('trainedClassifier')
because I want to use the model to predict new data in my GUIDE program. And here is the code I use to predict new data using the model
Img = handles.Abu;
[m,n,~] = size(Img);
axes(handles.axes1)
cla reset
set(gca,'XTick',[])
set(gca,'YTick',[])
imshow(Img);
%Below is the code I use to create mask to determine ROI of the image
h = imrect(gca, [10 10 750 750]);
setResizable(h,false)
wait(h);
mask = createMask(h);
%Below is the code I used to extract feature
Mean = mean2(Img(mask));
Std = std2(Img(mask));
Variance = var (double(Img(mask)));
Kurtosis = kurtosis(double(Img(mask)));
%Below is the I use to predict new data
T = table(Mean, Std, Variance, Kurtosis);
trainedClassifier = load('trainedClassifier.mat');
yfit = trainedClassifier.predictFcn(T);
%Below is the code I use to display the result into edit text
set(handles.edit1, 'String', Mean);
set(handles.edit2, 'String', Std);
set(handles.edit3, 'String', Variance);
set(handles.edit4, 'String', Kurtosis);
set(handles.edit5, 'String', yfit);
but I'm getting error Reference to non-existent field 'predictFcn'. How to fix this problem ? Is it possible to use a model which created from the Classification Learner apps in a GUIDE program ?
  1 Comment
Jahnavi  Samal
Jahnavi Samal on 23 Jan 2023
For me too getting the same error. Could u plz tell me how did u resolve it?

Sign in to comment.

Answers (1)

Jahnavi  Samal
Jahnavi Samal on 25 Jan 2023
Edited: Jahnavi Samal on 25 Jan 2023
While saving the training model from classificationLearner app the model gets imported into the workspace with a variable name. Use that variable name with predictFcn after loading the saved trainedmodel .mat file It worked for me.

Community Treasure Hunt

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

Start Hunting!