squares moving error in matlab

1 回表示 (過去 30 日間)
nctt
nctt 2023 年 12 月 24 日
編集済み: nctt 2023 年 12 月 27 日
so i am trying to write a code i want to move squares in other squares randomly,there is 10x10 squares. squares move but i dont know my code is true can you help? i cant share the whole code, because its a school project, i just want to know if this makes sense, its something like this (i added particle poisitons because i think thats the whole point and i forgot)
particle_positions = ones(num_of_particles, 2) * num_of_cells / 2 + 0.5
...
move_x = randi([-1, 1]);
...
if xnew < 1
xnew > num_of_cells ;
move_x = -move_x;
end

採用された回答

Image Analyst
Image Analyst 2023 年 12 月 24 日
This doesn't make any sense:
if xnew < 1
xnew > num_of_cells ;
move_x = -move_x;
end
It should be something like
if xnew < 1
% Don't let it go from 1 to 0
xnew = 1;
elseif xnew > num_of_cells
distancePast = xnew - num_of_cells;
xnew = num_of_cells - distancePast;
end
  3 件のコメント
nctt
nctt 2023 年 12 月 25 日
I want the squares to match the squares in the grid.. I used xline yline but its still the same
Image Analyst
Image Analyst 2023 年 12 月 26 日
Then you need to make sure the centers are on the 0.5 locations and go from the integer less than that to the integer more than that.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by