필터 지우기
필터 지우기

Simulink S-Function internal loop

조회 수: 3 (최근 30일)
Jacopo Riccio
Jacopo Riccio 2018년 1월 21일
편집: Mark Schwab 2018년 1월 26일
Hi, I need help, I hope some of you will be able to do it. I have just started using Matlab and Simulink for a thesis project. This is my problem: I am developing a control algorithm for an electrical machine. This algorithm requires to calculate an inverse matrix. To calculate the inverse I generated a file.c and a file.h in a "S-Function". There are two subroutines which call each other to calculate the inverse matrix. I run the subroutines by using devc++ compiler and it works properly. The matrix calculated by using devc++ is the expected one by doing several tests. But using it by simulink in a s-function, matlab crashes without any error message but I have to force to close matlab and restart it again. I am sure that the problem is caused by this loop between the subroutines because if I comment getting the sobroutine without loop matlab works properly.
I do hope I explained properly the problem and somebody will be able to help me. If you want I can send you the details about the codes. For now I have just wanted to understand if is something solvable by some tricks or using some simulink block to avoid it, or I must change algorithm to get the inverse matrix?
Thank you very much in advance

답변 (1개)

Mark Schwab
Mark Schwab 2018년 1월 26일
편집: Mark Schwab 2018년 1월 26일
There are several functions for taking the inverse of matrix in MATLAB. You can use a MATLAB function block in your model to take the inverse of an input matrix. I attached a picture of a simple model I made to demonstrate this workflow. The MATLAB function block contains the following code:
function y = fcn(u)
y = inv(u);
I have included links to documentation for the MATLAB function block and a couple of useful inverse functions below:
In regards to creating a C S-function in Simulink, the process for manually creating an S-function can be rather particular. I have included documentation below for tools we have to make this process easier if you are still interested in using C S-functions:

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by