how to randomly choose some values from specific variable

Respuestas (1)

James Tursa
James Tursa el 15 de Jun. de 2015
Editada: James Tursa el 15 de Jun. de 2015
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 comentarios

muhammad ismat
muhammad ismat el 15 de Jun. de 2015
Editada: Image Analyst el 15 de Jun. de 2015
also
values=s(end,randperm(size(s,2), 3)
thank you very much
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 15 de Jun. de 2015

Comentada:

el 15 de Jun. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by