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 次查看(过去 30 天)
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?

采纳的回答

Stephen23
Stephen23 2018-7-25
vec = setdiff(vec,B,'stable')

更多回答(1 个)

Dimitris Kalogiros
Dimitris Kalogiros 2018-7-25
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)]);

类别

Help CenterFile Exchange 中查找有关 Install Products 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by