How to delete k in random n set number?

Answers (1)

Use randperm to shuffle the numbers 1 through 20 and simply select the next element not yet chosen each time you need a random k.

3 Comments

Thank you for answering ..
but I still find errors in my math code
here I am deaf in the mathlab code
clc;clear;close all;
c=[10 2 20 11
12 7 9 20
4 14 16 18];
s=[15
25
10
];
d=[5 15 15 15];
[m,n]=size(c);
x=zeros(m,n)
phi=1:m*n
while phi
k= randi(length(phi))
i=round(1+(k-1)/n)
j=[1+mod((k-1),n)]
x(i,j)=min(s(i),d(j))
s(i)= s(i)-x(i,j)
d(j)= d(j)-x(i,j)
end
I am also confused about which form of loop I should use between for or while .. because I still have problems, someone can provide a math code solution from Step 2.1 to Step 2.4, thanks
randi generates numbers with replacement. randperm generates numbers without replacement.
rng default
x1 = randi(10, 1, 10)
x2 = randperm(10)
x1 contains the number 10 four times and doesn't contain 4, 5, or 8 at all.
x2 contains each number from 1 to 10 exactly once. You can iterate over the elements of that vector like so:
x2 = randperm(10);
for k = x2
fprintf("Processing element %d.\n", k)
end
% or
M = zeros(10);
for ind = 1:10
M(ind, x2(ind)) = ind;
end
disp(M)
Thank you for the answer
clc;clear;close all;
c=[10 2 20 11
12 7 9 20
4 14 16 18];
s=[15
25
10
];
d=[5 15 15 15];
[m,n]=size(c);
x=zeros(m,n)
phi=1:m*n
while phi
k= randi(length(phi))
i=round(1+(k-1)/n)
j=[1+mod((k-1),n)]
x(i,j)=min(s(i),d(j))
s(i)= s(i)-x(i,j)
d(j)= d(j)-x(i,j)
end
want to ask again .. from my math lab code to repeat steps 2.1 to 2. 4 what do you use?
please help for the solution

Sign in to comment.

Categories

Find more on Share and Distribute Software in Help Center and File Exchange

Asked:

on 29 Sep 2020

Commented:

on 29 Sep 2020

Community Treasure Hunt

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

Start Hunting!