How to Initialize parameters?
- From: Ahmad <ahmad_m_eid@xxxxxxxxx>
- Date: Sun, 30 Oct 2005 20:10:47 -0400
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?
.
- References:
- Prev by Date: how to process the ASCII files
- Next by Date: Re: how to process the ASCII files
- Previous by thread: Re: How to create M-File Mask in Simulink?
- Next by thread: Alternative to equalize function of MATLAB 7
- Index(es):
Relevant Pages
|