Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
% ===============================================
function [xrand,idrand] = randomize(x,id)
% randomize Randomize a vector of test conditions x with corresponding IDs
%
% Synopsis: xrand = randomize(x)
% [xrand,idrand] = randomize(x)
% [xrand,idrand] = randomize(x,id)
%
% Input: X = vector of values to be put in random order
% id = optional vector if IDs for the x data
%
% Output: xrand = values of the x vector in random order
% idrand = optional vector of ID values for to the elements in x
% If no id vector is supplied, but idrand is expected as
% a return value, generate the IDs as sequential integers
% -- Generate a random vector, sort it, and save the sort order.
irand = randperm(length(x)); % randomized list of integers
[junk,isort] = sort(irand); % isort is the sort order for the integers
xrand = x(isort);