How to count the number of objects within an area after simulink simulation ends
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Nhan Ngo
el 2 de En. de 2018
Comentada: Nhan Ngo
el 9 de En. de 2018
In the sldemo_eml_galaxy_script default simulink program, it draws a simulation of two galaxies interacting. Is there a way in which I can add another function block which waits until the end of the simulation and then counts how many objects are within a certain volume of the center of a galaxy I choose?
0 comentarios
Respuesta aceptada
Anh Tran
el 4 de En. de 2018
Yes, of course. After looking at Model Description, I noticed that the galaxy cores are treated as heavy bodies. Therefore, this particular example has 2 heavy bodies and 698 light bodies (stars). You may want to find the position of a heavy body, and find all the stars that satisfy your bounding condition. Check 'heavy1' output from "Apply Gravity" block for cores position.
For box area example, (x1 < box_width < x2) && (y1 < box_height < y2). You can use logical indexing or find() Since you only want your code to execute at the end of the simulation, you may pass a clock input into your function and do:
if clock == end_time % 250 in the example
% find position of core
% find stars in an area around core
end
Hope this helps. Good luck!
Más respuestas (0)
Ver también
Categorías
Más información sobre General Applications en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!