From: Jimmy on
Hi,

I would like to input .MAT file to Embedded Matlab Function in Simulink.
The.MAT file contains 2 rows. Row 1 is time and row 2 is amplitude value.
Would you please advise how I can do this? I cannot get it to work.

thank you
From: Guy Rouleau on
"Jimmy " <royalflush_cc(a)yahoo.com> wrote in message <hq4k28$g34$1(a)fred.mathworks.com>...
> Hi,
>
> I would like to input .MAT file to Embedded Matlab Function in Simulink.
> The.MAT file contains 2 rows. Row 1 is time and row 2 is amplitude value.
> Would you please advise how I can do this? I cannot get it to work.
>
> thank you

I depends on what is your goal:

- For simulation purpose only and if you want all the data in the MAT-file at the beginning of the simulation, you can declare LOAD as extrinsic and load the MAT-file in EML. You should include some logic to load it only once and keep the data as persistent.

- if you want to use in EML the amplitude (data in column 2) at the time specified in column 1, then you should use a From File block in simulink and connect the input of this block as an input to the EML block as any other signal.

I hope this helps.

Guy
From: Jimmy on
Guy,
Thanks for your reply.
I would like to use the amplitude values (Row 2) at the time specified at row 1.
I used the "from file" block and connect it to the EML, but I don't think the EML recognized the matrix from the .mat file. I tried to use the command length(u) and it does not return the correct value. Is it possible that I have to change some settings in EML for the input to recognize matrix or vector input?

thanks


"Guy Rouleau" <guy.rouleau.nospam(a)mathworks.com> wrote in message <hq5f35$do9$1(a)fred.mathworks.com>...
> "Jimmy " <royalflush_cc(a)yahoo.com> wrote in message <hq4k28$g34$1(a)fred.mathworks.com>...
> > Hi,
> >
> > I would like to input .MAT file to Embedded Matlab Function in Simulink.
> > The.MAT file contains 2 rows. Row 1 is time and row 2 is amplitude value.
> > Would you please advise how I can do this? I cannot get it to work.
> >
> > thank you
>
> I depends on what is your goal:
>
> - For simulation purpose only and if you want all the data in the MAT-file at the beginning of the simulation, you can declare LOAD as extrinsic and load the MAT-file in EML. You should include some logic to load it only once and keep the data as persistent.
>
> - if you want to use in EML the amplitude (data in column 2) at the time specified in column 1, then you should use a From File block in simulink and connect the input of this block as an input to the EML block as any other signal.
>
> I hope this helps.
>
> Guy
From: Guy Rouleau on
You have a matrix of 2 columns. Each element of column 2 correspond to a time value in column 1.

In this case, the From File block will not output a matrix. At each time step, it will output a scalar value (the amplitude value corresponding to the time specified in colum 1) and this is what the EML block will receive. The EML block will then receive a new scalar every time step.

So doing length(u) in EML should return 1.

I am not sure I understand why you expect the EML block to receive a matrix or vector because you say "I would like to use the amplitude values (Row 2) at the time specified at row 1"

Am I missing something?

Guy

"Jimmy " <royalflush_cc(a)yahoo.com> wrote in message <hq74q0$g4b$1(a)fred.mathworks.com>...
> Guy,
> Thanks for your reply.
> I would like to use the amplitude values (Row 2) at the time specified at row 1.
> I used the "from file" block and connect it to the EML, but I don't think the EML recognized the matrix from the .mat file. I tried to use the command length(u) and it does not return the correct value. Is it possible that I have to change some settings in EML for the input to recognize matrix or vector input?
>
> thanks
>
>
> "Guy Rouleau" <guy.rouleau.nospam(a)mathworks.com> wrote in message <hq5f35$do9$1(a)fred.mathworks.com>...
> > "Jimmy " <royalflush_cc(a)yahoo.com> wrote in message <hq4k28$g34$1(a)fred.mathworks.com>...
> > > Hi,
> > >
> > > I would like to input .MAT file to Embedded Matlab Function in Simulink.
> > > The.MAT file contains 2 rows. Row 1 is time and row 2 is amplitude value.
> > > Would you please advise how I can do this? I cannot get it to work.
> > >
> > > thank you
> >
> > I depends on what is your goal:
> >
> > - For simulation purpose only and if you want all the data in the MAT-file at the beginning of the simulation, you can declare LOAD as extrinsic and load the MAT-file in EML. You should include some logic to load it only once and keep the data as persistent.
> >
> > - if you want to use in EML the amplitude (data in column 2) at the time specified in column 1, then you should use a From File block in simulink and connect the input of this block as an input to the EML block as any other signal.
> >
> > I hope this helps.
> >
> > Guy
From: Jimmy on
Guy,

You are absolutely correct. Length (u) returns a value of 1. I thought before that "from file" block outputs a matrix, but you have convinced me that it does not work that way.

I probably did not explain what I wanted to do very well. Basically, the ultimate goal is to create a simulink block that takes sample input signal and outputs the magnitude and phase of the signal (much like Discrete Fourier Filter block on SimpowerSystem). However, I am not allowed to use the discrete fourier filter block (since this is a school assignment and the prof. does not allow us use that block). Instead, I need to write my own code in simulink.

To accomplish this, I think the first step is to get the amplitude values of the signal at every sampling instance. So lets say the sampling time is 1/1000, I will need to get the amplitude values of the signal at time 0, 1/1000, 2/1000, 3/1000, and so on until the signal ends.

There is no requirement to use EML or even to use .MAT file. It was just my idea.
I would appreciate if you have any suggestion.

Thanks again for replying my question.



"Guy Rouleau" <guy.rouleau.nospam(a)mathworks.com> wrote in message <hq76ev$g3p$1(a)fred.mathworks.com>...
> You have a matrix of 2 columns. Each element of column 2 correspond to a time value in column 1.
>
> In this case, the From File block will not output a matrix. At each time step, it will output a scalar value (the amplitude value corresponding to the time specified in colum 1) and this is what the EML block will receive. The EML block will then receive a new scalar every time step.
>
> So doing length(u) in EML should return 1.
>
> I am not sure I understand why you expect the EML block to receive a matrix or vector because you say "I would like to use the amplitude values (Row 2) at the time specified at row 1"
>
> Am I missing something?
>
> Guy
>
> "Jimmy " <royalflush_cc(a)yahoo.com> wrote in message <hq74q0$g4b$1(a)fred.mathworks.com>...
> > Guy,
> > Thanks for your reply.
> > I would like to use the amplitude values (Row 2) at the time specified at row 1.
> > I used the "from file" block and connect it to the EML, but I don't think the EML recognized the matrix from the .mat file. I tried to use the command length(u) and it does not return the correct value. Is it possible that I have to change some settings in EML for the input to recognize matrix or vector input?
> >
> > thanks
> >
> >
> > "Guy Rouleau" <guy.rouleau.nospam(a)mathworks.com> wrote in message <hq5f35$do9$1(a)fred.mathworks.com>...
> > > "Jimmy " <royalflush_cc(a)yahoo.com> wrote in message <hq4k28$g34$1(a)fred.mathworks.com>...
> > > > Hi,
> > > >
> > > > I would like to input .MAT file to Embedded Matlab Function in Simulink.
> > > > The.MAT file contains 2 rows. Row 1 is time and row 2 is amplitude value.
> > > > Would you please advise how I can do this? I cannot get it to work.
> > > >
> > > > thank you
> > >
> > > I depends on what is your goal:
> > >
> > > - For simulation purpose only and if you want all the data in the MAT-file at the beginning of the simulation, you can declare LOAD as extrinsic and load the MAT-file in EML. You should include some logic to load it only once and keep the data as persistent.
> > >
> > > - if you want to use in EML the amplitude (data in column 2) at the time specified in column 1, then you should use a From File block in simulink and connect the input of this block as an input to the EML block as any other signal.
> > >
> > > I hope this helps.
> > >
> > > Guy