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 views (last 30 days)
Show older comments
nurhayat sahinkaya
on 25 Jul 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 Comments
Accepted Answer
More Answers (1)
Dimitris Kalogiros
on 25 Jul 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 Comments
See Also
Categories
Find more on Install Products in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!