When plotting figures random in a figure, how can you make sure they dont overlap?
1 回表示 (過去 30 日間)
古いコメントを表示
I am making a visual search task in Matlab.
For this Im plotting random figures (X or O) with the colour blue or red in a figure. Im using 'rand' to asign a location between 0 and 1. How can I make sure that the plotted symbols do not overlap?
This is my function to plot multiple symbols random in a plot;
function put_symbol_infigure(s, k, m)
% This function puts a letter (symbol) s at a random location loc in figure
% The figure goes from 0 to 1 with the colour k
% m = how many times the symbol is plotted in the figure
% loc1 is the x-coordinate, loc2 is the y-coordinate
% s = string, example given: 'X' or 'O'
% k = string that gives the colour, example given: 'g' or 'r'
for i = 1:m
% random location between 0 and 1 is given to the y and x coordinate
loc(1) = rand;
loc(2) = rand;
% Location and symbol are given to variable g
g=text(loc(1), loc(2), s);
% Figure is made with all the given requirements
set(g, 'color', k);
end
end
0 件のコメント
回答 (1 件)
Sindhu Karri
2020 年 11 月 13 日
Hii,
“RandStream” function can be used to set different seeds to generate different numbers and avoid overlap between symbols.
Refer the link below, for detailed information:
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!