How to import KNN-model structure from matlab into simulink

조회 수: 2 (최근 30일)
frank wetzels
frank wetzels 2024년 7월 25일
답변: Aneela 2024년 8월 18일
All,
The problem I am facing is a move of KNN-model data structure from matlab to simulink in a loop:
In matlab TrainingData is used as input to create an KNN based-model. In simulink, at some point, I want to use this model to predict the outcome of a certain decision based on certain parameters that evolve during simulation. If the simulation ends, the outcome of the decsion is used in matlab to adjust the TrainingData and to update the KNN-model. The updated KNN-model will be used for the next simutlation.
Note that before the loop starts, the feature table exists.
Note that in matlab, the knn-model data is the outcome of the command: knnmodel = fitcknn(TrainingData, 'feature'). So i need to import this knnmodel structure into simulink.
My problem is that I do not see how to successfully import such KNN-model into the simulink model for decision making (prediction).
Is there any method to get this done?

답변 (2개)

Aneela
Aneela 2024년 7월 26일
  댓글 수: 1
frank wetzels
frank wetzels 2024년 7월 31일
Thanks for your response.
Is there an alternative by, for example, reading the model from the global workspace since I want to use the simulink model in a loop? The reason for having the loop is to be able to do all kinds of administrative stuff in matlab itself before and after running the model.
Regards,
Frank

댓글을 달려면 로그인하십시오.


Aneela
Aneela 2024년 8월 18일
Global workspace can be used facilitate the use of a Simulink model in a loop. Here is the possible workaround:
  1. Ensure that KNN model is trained and stored in the global workspace.
  2. Set up the simulink model as described in the documentation: https://www.mathworks.com/help/stats/predict-class-labels-using-classification-knn-predict-block.html#:~:text=testAccuracy%20%3D%200.9333-,Create%20Simulink%20Model,-Create%20a%20new
  3. Create a structure array for the input data.
  4. Configure the Simulink Model for input using Configuration Parameters dialog box.
  5. Create a MATLAB script that automates running the Simulink model in loop.
  6. Use the results from each iteration to adjust the model.

카테고리

Help CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by