필터 지우기
필터 지우기

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 CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by