MATLAB Answers


I have a knn classification model.i want to simulate the same in simulink

Asked by pavan sunder on 13 Dec 2016
Latest activity Commented on by Sean de Wolski
on 14 Dec 2016
I have a knn simulation model. I used functions fitcknn and predict in my script...i want to simulate the same in smulink..kindly suggest me which block to be used for fitcknn and predict in simulink


Sign in to comment.


1 Answer

Answer by Sean de Wolski
on 13 Dec 2016

You could use the MATLAB function block to call your KNN model from Simulink.


i tried the same not working. i am unable take the KNN model as input. kindly help me with a more detail explanation..
i wrote the following code in my matlab function block
function y = KNNclass(mdl2,ts)
the error messagee i received is
Unsupported input format for From Workspace block 'tt/From Workspace'. Available formats are double non-complex matrix, a structure with or without time, or a structure with MATLAB timeseries as leaf nodes. All formats require the data to be finite (not Inf or NaN).
It shouldn't be in the from workspace block, it should be in a MATLAB function block. Here's how I would set it up. Note that the knn classifier is already trained and stored in a MAT file. You could swap that out to a call to train it if necessary.

Sign in to comment.