How to count the number of objects within an area after simulink simulation ends

1 回表示 (過去 30 日間)
Nhan Ngo
Nhan Ngo 2018 年 1 月 2 日
コメント済み: Nhan Ngo 2018 年 1 月 9 日
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?

採用された回答

Anh Tran
Anh Tran 2018 年 1 月 4 日
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!
  1 件のコメント
Nhan Ngo
Nhan Ngo 2018 年 1 月 9 日
Thanks. Since you seem to be aware of the program, it would be helpful if I could get a little more clarification on how the heavy bodies and light bodies are arranged, partitioned, and how they are plotted. I've looked at all the function blocks and I am a bit stumped on how they are created and how to find the position of the heavy bodies and count the number of light bodies in the range. Also, what does x1,x2,y1,y2 mean in your code example above? I attempted to constrain the area by the code following but everything in-between I don't know how to resolve.
function mass = massfromradius(heavy1,light1,clock,simulationtime)
SolarMass = 1.9891e+30;
mass = 0;
if clock == simulationtime
% some code to find the position?
for (x1<30000<x2)&&(y1<30000y2)
% something here I'm not quite sure of to find position of light bodies
particles = sum(x(:) == 1);
mass = particles*solarmass;
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGeneral Applications についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by