I am trying to randomize a marker color
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a graph that randomizes a point on the graph. I am also trying to randomize the marker color and edge color but then never change. He is what i have but I dont know how to fix it.
3 comentarios
Respuestas (2)
Maik
el 7 de Nov. de 2022
Editada: Maik
el 7 de Nov. de 2022
I assume the randi in your program was the problem. Here below we use it to generate a single
value everytime and pass it to the markersize plot handle.
close all
x = sin(0:2*pi/100:2*pi);
figure;
plot(x, '-b*');
markerSize = [1:10];
% randi syntax [1,10] range of numbers to choose the random value,
% 1,1 - number of random values to generate
rand_idx = randi([1,10],1,1);
randMarkerSize = markerSize(rand_idx);
figure;
h = plot(x, '-b*')
h.MarkerSize = randMarkerSize;
0 comentarios
Walter Roberson
el 8 de Nov. de 2022
'b':'r':'g'
You have used the colon operator. 'b' <= 'g' so you get at least one value, but 'b' + 'r' > 'g' so you only get one value, the 'b'
You perhaps wanted ['b', 'r', 'g'] -- which is exactly the same as 'brg' in MATLAB.
You randi(5) but 5 has no relationship to the number of marker colors you have to select from. You should numel() the color vector to find the number of items to select from. Then once you have your random number, use it to index the color array.
disp random_markerSize
Notice that displays the literal text random_markerSize . If you want to display the content of the variable random_markerSize then you need to use disp(random_markerSize)
0 comentarios
Ver también
Categorías
Más información sobre Discrete Data Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!