Using global variables in Embedded Matlab function in simulink

Hi,
I am using data store memory blocks in conjunction with global variables to use global variables in embedded matlab function in simulink. I have 4 global variables and therefore I have 4 data storage memory blocks in my simulink model. However, when I ran my simulation, the values of the global variables were not taken from the data storage block and instead I got a warning which says:
Warning: The block 'Embedded MATLAB Function' is reading from element 0 of the data store 'Data Store Memory' before any blocks have written to this memory in a minor time step at time 400.0
400 - is my simulation time.
I do not understand the reason why I am receiving this message and the reason for the values of the global variables not being updated from the data storage :(
It would be great if any of you could advice or suggest me on this.
Thanks

3 Comments

Additional details:
I have more than one global variable and I am using separate data store memory blocks for each of them. However, few of the variables are shows values as zero when it is displayed even though I had given it some numerical value. Its not taking the value from the data store block. I am also receiving the above warning message every time.
I am not confident, but try to write the Data store Memory with 'Data store write' block, see its work or not.
Can you post code of your embedded matlab function block.

Sign in to comment.

 Accepted Answer

Hi Muthappa
Make sure that you are ensuring following steps while using global variables with embedded matlab.
[EDITED]
Data Store memory is used to hold the data value only. To write the data to it a Data Store Write block with same name is required. Similarly, to read the data from it a Data Store read is required.
You are reading from a Data Store memory block through global variable in EML function, so it is necessary to write some value in the memory first. Use Data Store Write block with the same name and write some value to it.
  • I tried first without Write block and got same warning as you.
  • I added Data store write block, and model runs without warning giving expected output.

4 Comments

@Tabrez. Your link is the right place for the information. My knowledge seems to be outdated so I'll remove my answer. Thanks!
Tabrez and Jiang,
Thanks a lot for helping me solve the problems. I really appreciate your help.
I started using the data store memory block after I read that. But, even though I have initialized all the 4 global variables, it doesn't reflect at all when I run my simulation. Only at the first clock time, it gives the initial value that I gave after which it gives me only zeros to one of the variable. I also get the above warning message. So I was wondering, if that warning message has to do something with that.
If you get to know anything about it, please let me know.
See Edited part of this answer.
Thank You Tabrez. It works for me now :)
Have a nice day!!

Sign in to comment.

More Answers (1)

Those are just warnings. If you are sure that you don't write to the memory as often as you read it, you can disable the warning.
Go to Simulink model, select menu Simulation->Configuration Parameters...->Diagnostics->Data Validity, in the "Data Store Memory Block" section.

1 Comment

Thank you Jiang,
Its definitely useful to me as such warnings would not let me read my output clearly.
Have a nice day!!

Sign in to comment.

Asked:

on 28 Sep 2011

Community Treasure Hunt

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

Start Hunting!