フィルターのクリア

Simple programming question about randomizing a vector.

2 ビュー (過去 30 日間)
Helen Kirby
Helen Kirby 2017 年 1 月 14 日
コメント済み: Helen Kirby 2017 年 1 月 14 日
clc
clear
ones = ones(1,20);
twos = ones+1;
thrs = twos+1;
fors = thrs+1;
fivs = fors+1;
Nums = [ones twos thrs fors fivs];
This should be dead easy but I cannot find a command to do it. Having got my blocks of 1s,2s,3s,4s,5s, in a single vector(Nums) I would now like to scramble them so that they are all mixed up. I tried "random" and "shuffle" but they gave me errors. Does anyone know how else I can randomize or shuffle up Nums?

採用された回答

Image Analyst
Image Analyst 2017 年 1 月 14 日
Try randperm():
% Get new indexes all scrambled up.
randomIndexes = randperm(length(Nums));
% Extract those indexes into a new vector.
scrambledNums = Nums(randomIndexes)
  1 件のコメント
Helen Kirby
Helen Kirby 2017 年 1 月 14 日
Yep, that did it! Thank you SO much - and so fast too. Very clever. HK.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by