I have a variable vector like the active: [2 3 4] vector. I select a random element (B) from the active set and use it in a different vector. What function can I use to delete the randomly selected (B) value from the active vector?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
nurhayat sahinkaya
le 25 Juil 2018
Réponse apportée : Stephen23
le 25 Juil 2018
I have a variable vector like the active: [2 3 4] vector. I select a random element (B) from the active set and use it in a different vector. What function can I use to delete the randomly selected (B) value from the active vector?
0 commentaires
Réponse acceptée
Plus de réponses (1)
Dimitris Kalogiros
le 25 Juil 2018
Suppose you have a vector x and you want to select , use and then delete a random element of it.
Have a look at the following :
close all; clc;
% create a vector x
x=10:10:100;
disp(['initial value of x = ' num2str(x)]);
% choose a random element of x
random_index=randi(length(x));
% take your element
y=x(random_index);
disp(['chosen value y = ' num2str(y)]);
% remove this specific element from vector x
x(random_index)=[];
disp(['final value of x = ' num2str(x)]);
0 commentaires
Voir également
Catégories
En savoir plus sur Install Products 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!