How to access variable values at certain times in simulink

14 visualizaciones (últimos 30 días)
Nhan Ngo
Nhan Ngo el 22 de Feb. de 2018
Comentada: Nhan Ngo el 5 de Mzo. de 2018
I'm writing this code that takes an output after a simulation is over for x y z positions. When I use the simout block, it says the data is [1x2000x501 double], 2000 x y or z positions for 2000 elements and 501 times. I want the variable value at 0 time and 500 time, but when I say x(1,1:2000,501) for instance, x doesn't contain any time values so it gives me an error. The little notes in simulink also say the value is only 1,2000, and I know it is because when I accessed x at different times it always came out at the same value even though the x position changes. How do I extract the value at a certain time?

Respuestas (1)

Sujit Muduli
Sujit Muduli el 5 de Mzo. de 2018
Hi Nahn,
Could you please let me know about the format how simout block is storing the data? Are you storing it differently for x, y and z positions?
Again when you said x(1,1:2000,501) which x you are referring to here? Please attach necessary files so I could have a look at it.
Thanks, Sujit
  1 comentario
Nhan Ngo
Nhan Ngo el 5 de Mzo. de 2018
The function block I am creating comes from the default sldemo_eml_galaxy_script. I created a function block which takes the data from the "Merge heavy and light bodies" block. The output is 2000x8 (because I changed the amount of particles in each galaxy to 1000).
bodies_X = M(2001:4000); % x coordinate of all bodies
bodies_Y = M(4001:6000); % y coordinate of all bodies
bodies_Z = M(6001:8000); % z coordinate of all bodies
%Insert code to compare these X, Y and Z coordinates to the position
%and dimensions of the bounding volume
mass = bodies_X(500)
When I say boxies_X(scalar) it comes out with a scalar answer, same with (1,500) for instance. However, when I use the "output to workspace" block on that as well it comes out as 2000 x 8 x 250 time series. But, when I try to access the values at time it comes out with a dimension error. However, when I increase the simulation time it changes the value, which means that it is taking the last point of data before it ended, but I cannot access values in the in between times without changing the simulation time. Does time series not mean that I have data for those points, and it just indicates how long it was run?

Iniciar sesión para comentar.

Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by