When plotting figures random in a figure, how can you make sure they dont overlap?

1 visualizzazione (ultimi 30 giorni)
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

Risposte (1)

Sindhu Karri
Sindhu Karri il 13 Nov 2020
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:

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by