I am trying to randomize a marker color
21 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
Maik
le 7 Nov 2022
Modifié(e) : Maik
le 7 Nov 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 commentaires
Walter Roberson
le 8 Nov 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 commentaires
Voir également
Catégories
En savoir plus sur Discrete Data Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!