MATLAB: Assign a number of random elements to different variables

arraysrandom

How can I assign integers from 1 to 40 randomly to six different variables such that they don't repeat in any of the arrays and no number gets left out?
The array size of each variable should be random as well.
An approach I have considered is using
v = randperm(40);
a = randi([1,40])
Sat1 = v(1:a)
b = randi([a,40])
Sat2 = v(a+1:b)
c = randi([b,40])
Sat3 = v(b+1:c)
d = randi([c,40])
Sat4 = v(c+1:d)
e = randi([d,40])
Sat5 = v(d+1:e)
f = randi([e,40])
Sat6 = v(e+1:f)
But then the problem is in some generations will lead to empty arrays or even unassigned integers! Any ideas?

Best Answer

v=randperm(40);
k=[];
while isempty(k)
a=randi(40,1000,6);%you could change 40 to something smaller if you want to limit the maximum
b=sum(a,2);
k=a(b==40,:);
end
k=k(1,:);
c=1;
for m=1:6
Sat{m}=v(c:c+k(m)-1);
c=c+k(m);
end