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

조회 수: 4 (최근 30일)
Imme Kooi
Imme Kooi 2020년 11월 10일
답변: Sindhu Karri 2020년 11월 13일
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

답변 (1개)

Sindhu Karri
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:

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by