Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Simulnk : data array bounds error

Subject: Simulnk : data array bounds error

From: Richard Dickinson

Date: 22 Sep, 2009 09:52:01

Message: 1 of 2

Hi folks, wonder if soneone can help with this, searched the forum but nothing shows up...

I'm a novice simulink user, but use matlab regularly.

basically I had a matlab function which I wished to put into simulink with the intention of it being autocoded at a later date.

I used the embedded matlab block and worked my way through all the error messages - lots to do with growing arrays etc and basically changed my vectorised code to more fortran or C like code. It now can start to run in simulink, so 1st hurdle overcome !

So to the problem, in the embedded matlab code I have :

%variable initialisations and declarations
myvariable=0;
myvariable(1:100)=0; <-- This gets an error message

I tried putting it into a more code like loop

for tmpi=1:100
  myvariable(tmpi)=0; <--- gets same error message.
end

The Simulation diagnostics comes up with:
Embedded Matlab interface error : Simulation stopped due to data array bounds read error"

The variable is neither an input nor an output from the EM block

So I'm now a bit stumped, surely embedded matlab can cope with arrays ?

I don't understand why I'm getting this error message

can anyone assist please ?

thanks

Subject: Simulnk : data array bounds error

From: Phil Goddard

Date: 22 Sep, 2009 18:51:02

Message: 2 of 2

EML can't cope with resizing arrays -- just as in C you need to specify how much memory to use in advance.

> %variable initialisations and declarations
> myvariable=0;
> myvariable(1:100)=0; <-- This gets an error message

The first line above says myvariable is 1-by-1, then the second says it's 1-by-100.
EML does not allow that.

Combine the 2 lines into
myvariable = zeros(1,100);

Note that you cannot index into an array until it has been defined, so using
myvariable(1:100) = 0
instead of the above will _not_ work either.

Phil.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us