S_Function - Process modeling help

Hi,
I am trying simulate a process (MSF Desalination) using s_function in simulink. Since I am new to simulink, I have the following doubts.
The system I have has 108 states and 234 outputs and inputs each. The states are discrete and I am using my own derivative calculation functions to calculate the state values at the next time step. The outputs that I calculate at each time instant is to be used in the next time instant for calculation.
a) When I try running the model, I get the error message saying: "Output returned by S-function xxxxx during flag=3 call must be a real vector of length 234". What should be done to correct this?
b) The s_function code I have written is given:
Any help really appreciated. Thanks for your time.
function [sys,x0,str,ts] = MSF_sfcn(t,x,u,flag)
switch flag
% Initialization
case 0
clc
[sys,x0,str,ts] = mdlInitializeSizes;
% Calculation of derivatives
% case 1
%
% sys = dynamic_MSF(x);
%
case 2
% Write here the code to call a function which will calculate the
% derivatives at that time instant. This should return just the
% states
sys = mdlUpdate(t,x,u);
%
% sys
% Output
case 3
% Write here the code to call a function that will update the
% values of all the flow rates and other variables. These
% recalculated variables will be the output.
sys = mdlOutputs(t,x,u);
case {1 4 9} % Unused flags
sys = [];
otherwise
error(['Unhandled fag =',num2str(flag)]);
end

Answers (0)

Categories

Find more on Parallel Computing Toolbox in Help Center and File Exchange

Asked:

on 20 Apr 2014

Community Treasure Hunt

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

Start Hunting!