MATLAB: Random split of a vector of unequal lengths random numberssplit How can I split a vector in k unequal subsets? For example, if I have 200 data, a random split might give us 63, 95 and 150. That is 1:63, 64:95, 96:150 and 151:200. Apology for cross postings. Best Answer k=4v=1:200m=numel(v);idx=unique([randperm(m-2,k)+1 m]);idx0=[1 idx(1:end-1)+1];out=arrayfun(@(ii,jj) v(ii:jj),idx0,idx,'un',0);celldisp(out) Related SolutionsMATLAB: How to randomly select variable from the range of numbers a=[1:1:100] out=a(randi(100,1,5)) MATLAB: How to select a random number from set 5:20:2000 idx=5:20:2000;rand_num=idx(randi(length(idx))); Related QuestionInsert zeros in a vectorHow to set pixel values in 100*100 matrixRandom numbersSelecting values randomly from datasetHow to divide a long vector into several vectors of known length
Best Answer