Randomly assort variables into 3xN matrix
Show older comments
I need a 3xN matrix that for example:
1 2 3 4 ... 10 ... 20
x: .5 .5 .5 .5 .5 .1
y: constant
z: canstant
I have 3 values of x that need to be random every 10 columns so like .5 for 1:10 then .1 for 11:20, then maybe it goes back to .5 for 21:30, then to 1 for 31:40
Answers (1)
dpb
on 7 Jul 2022
V=[v1;v2;v3]; % a vector of the three possible values (set elsewhere somehow; not explained)
ix=randperm(3); % the randomized permutation of the three
x=cell2mat(arrayfun(@(i) repmat(V(i),1,size(x,2)/10),ix,'uniformoutput',0));
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!