How to Initialize parameters?



Thank you very much...
I'm sorry, I didn't explain well what I want..

I want to put and initialize the parameters values (like R, L, C,
....) in an M-file, instead of writing each parameter value in
Simulink blocks..

Always, any given example ask to double click on mask block to M-file
before running the Simulik file.

Thanks a lot
----------------------------------------
----------------------------------------

R wrote:
>
>
> I guess what you want to do is to change the parameter values of an
> .m file inside your simulink model by entering the values in a
> mask.
> If that is the case you have to write your .m -file as an
> S-function.
> This is a bit tricky.
> A simple way is to copy and paste the following code and save it as
> .m file. Write your matlab stuff where I have put "PUT THE YOUR
> CODE
> BELOW".
> Now go to "User-Defined Function" in Simulink library browser and
> copy and paste the "s-function" block in your model. Now open the
> s-function block in your model and put the name of your function
> (without the extension .m).
> This runs your .m file inside your simulink model. It has one input
> vector ('u') and one output vector ('sys').
> First run your model to make sure that your s-function works well.
>
> In order to enter parameters to this s-function and change it with
> a
> mask, you have to put a 'constant' block in front of your
> s-function.
> Now mask both your s-function and your 'constant' block together.
> Now
> you can change the parameters of your 'constant' block in your
> mask.
> This will change the value of the constant block and it will go go
> to
> your .m file as an input and is used there.
>
> Good luck.
>
>
>
> Here is a simple S-function sample for your .m file.
>
> % *****************************************
> function [sys,x0,str,ts] = My_M_File_Name(t,x,u,flag)
>
> % ****************************************************
> % Begining of S function format
> % ****************************************************
> switch flag,
> case 0
> [sys,x0,str,ts] = mdlInitializeSizes;
> case 3
> sys = mdlOutputs(t,x,u);
> case { 1, 2, 4, 9 }
> sys = [];
> otherwise
> error(['Unhandled flag = ',num2str(flag)]);
> end;
>
> % **********
>
> function [sys,x0,str,ts] = mdlInitializeSizes
>
> % Call function simsizes to create the sizes structure.
> sizes = simsizes;
> % Load the sizes structure with the initialization information.
> sizes.NumContStates= 0;
> sizes.NumDiscStates= 0;
> sizes.NumOutputs= -1; % Dynamic size output
> sizes.NumInputs= -1; % Dynamic size input
> sizes.DirFeedthrough=1;
> sizes.NumSampleTimes=1;
> % Load the sys vector with the sizes information.
> sys = simsizes(sizes);
> %
> x0 = []; % No continuous states
> %
> str = []; % No state ordering
> %
> ts = [-1 0]; % Inherited sample time
> % End of mdlInitializeSizes.
>
> %==========================================================
> % Function mdlOutputs performs the calculations.
> %==========================================================
>
> function sys = mdlOutputs(t,x,u)
>
> % *****
> % PUT THE YOUR CODE BELOW
> % *****
>
> sys=u;
>
> Ahmad wrote:
>>
>>
>> Actually, I don't know how to make S-function?
>> Is it necessary?
>> What is the simplest way to make M-file mask in Simulink file?
> How?
>>
>> Thank you very much
>>
>> R wrote:
>>>
>>>
>>> Are you using M-file as an S-function in your simulink
model?
>>>
>>> --------------
>>>
>>> Ahmad wrote:
>>>>
>>>>
>>>> How can I insert a mask in simulink file for M-file
that
>>> containing
>>>> the parameters values used in a Simulink file?
.



Relevant Pages

  • Re: How to create M-File Mask in Simulink?
    ... ..m file inside your simulink model by entering the values in a mask. ... If that is the case you have to write your .m -file as an S-function. ... % Load the sizes structure with the initialization information. ...
    (comp.soft-sys.matlab)
  • Re: S-Function with M-File (M-Function BLOCK)
    ... %SFUNDSC2 Example unit delay M-File S-function ... %* DICHIARO GLOBALI ... %ssSetNumOutputPorts(sizes, 2); ... %sys = mdlUpdate; ...
    (comp.soft-sys.matlab)
  • Re: Accessing Mask Workspace from an S-function
    ... > I have a string variable passed to my s-function, ... > containing references to mask workspace variables (i.e. variables ... > defined within the mask that encapsulates the s-function). ...
    (comp.soft-sys.matlab)
  • masking level-2 m-file s-functions
    ... I'd like to create a mask for my m-file s-function (level-2), ... when i click on the block in the Simulink editor, the 'Mask ... At the moment I'm using a workaround, hiding the s-function block ...
    (comp.soft-sys.matlab)
  • S-Function Problem
    ... im new to Simulink and i have some problem with S-Function. ... Here are the command i have wrote: ... sys = simsizes; ...
    (comp.soft-sys.matlab)