create a vector w1 having the same length as another vector w but containing certain x values

3 vues (au cours des 30 derniers jours)
Hello! I want to create a vector w1 having the same length as another vector w but containing certain x values. How can I fix the code?
v = [100; 177; 186; 124; 175; 211; 132; 144; 124; 111; 133; 152];
w = [25; 14; 33; 20; 14; 22; 29];
number_w = height(w);
x = randsample(v,1);
% w1 = ?
  2 commentaires
Dyuman Joshi
Dyuman Joshi le 10 Fév 2023
So we have the values for x, but at which indices do you want to put them in w?
Alberto Acri
Alberto Acri le 10 Fév 2023
I want to get w1 in the following way:
w1 = [x; x; x; x; x; x; x]; % for example: w1 = [111; 186; 175; 211; 144; 177; 152];

Connectez-vous pour commenter.

Réponse acceptée

Dyuman Joshi
Dyuman Joshi le 10 Fév 2023
v = [100; 177; 186; 124; 175; 211; 132; 144; 124; 111; 133; 152];
w = [25; 14; 33; 20; 14; 22; 29];
w1=randsample(v,numel(w))
w1 = 7×1
152 124 100 124 111 175 177

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by