Reading out a Vector via a countermodel in simulink

Hi,
i have to give the single elements of a vector one after the other out. So I decided to build a countermodel.
The Counter works i connected it to a scope and it Counts up in steps of 0.01sec from 0 up to 39. It gives out the variable n.
Then i connected n to the following user-defined function:
Vector=[207;160;0;0;0;6;4;7;10;14;0;44;122;224;16;32;0;16;144;80;128;128;197;167;14;0;0;15;15;0;0;0;0;86;116;235;10;65;241]; Output=Vector(n,1);
The Output of the user-definned function is connected to a scope because i want to test if it works but when i start the Simulation i get following error:
Simulation stopped due to out of bounds error. Block MATLAB Function (#112) While executing: none
Can anyone help me?
Thanks a lot!
Greetings

 Respuesta aceptada

Mischa Kim
Mischa Kim el 26 de Feb. de 2014
Editada: Mischa Kim el 26 de Feb. de 2014
David, are you specifying a value for n? For example (for testing purposes) use the following Simulink model
with the following code inside the MATLAB function.
function y = fcn(n)
Vector = [207;160;0;0;0;6;4;7;10;14;0;44]; % vector cut off for readability
y = Vector(n,1);
You could specify n in the MATLAB function, or, as an external input for the function.

3 comentarios

David
David el 26 de Feb. de 2014
Hi Mischa,
i defined the value for n via the countermodel.
If i connect a Display like in your model the Display Shows off all values in the vector, and the following error Comes up when the last value got displayed: Simulation stopped due to out of bounds error. Block MATLAB Function (#112) While executing: None
Thanks!
Mischa Kim
Mischa Kim el 26 de Feb. de 2014
Make sure that you are indexing correctly. The first element of the vector is Vector(1), the last is Vector(39).
I am not sure, how you are doing the counting, but if you are using a standard Simulink counter, by default the initial output is 0. This can be "fixed" by simply adding a constant 1 to the counter output. If you do so, make sure the counter quits (limit) at 38 ( + 1 = 39 ).
David
David el 26 de Feb. de 2014
Thanks,it works!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Simulink en Centro de ayuda y File Exchange.

Preguntada:

el 26 de Feb. de 2014

Comentada:

el 26 de Feb. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by