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?
3 ビュー (過去 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?
0 件のコメント
採用された回答
その他の回答 (1 件)
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)]);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Install Products についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!