Simulink S-Function internal loop

2 次查看(过去 30 天)
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 Functions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by