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!