フィルターのクリア

how to randomly choose some values from specific variable

1 回表示 (過去 30 日間)
muhammad ismat
muhammad ismat 2015 年 6 月 15 日
コメント済み: Image Analyst 2015 年 6 月 15 日
consider a=[6 5 4 3 6 4 2 1]
i want some values from variable 'a' say[4 3 2]or 20% of variable a

回答 (1 件)

James Tursa
James Tursa 2015 年 6 月 15 日
編集済み: James Tursa 2015 年 6 月 15 日
E.g., if you want only a subset of your vector:
k = number of values you want; % Must be <= numel(a)
p = randperm(numel(a),k);
b = a(p);
If you want a sample that could include repeats, e.g.,
k = number of values you want;
p = randi(numel(a),1,k);
b = a(p);
  2 件のコメント
muhammad ismat
muhammad ismat 2015 年 6 月 15 日
編集済み: Image Analyst 2015 年 6 月 15 日
also
values=s(end,randperm(size(s,2), 3)
thank you very much
Image Analyst
Image Analyst 2015 年 6 月 15 日
OK -- you didn't say anything about "s" or a 2D matrix, but I think you should mark it "Accepted" anyway, to give James reputation points.

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

カテゴリ

Help Center および File ExchangeSimulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by