How to delete k in random n set number?

1 visualización (últimos 30 días)
Muhammad Sam'an
Muhammad Sam'an el 29 de Sept. de 2020
Comentada: Muhammad Sam'an el 29 de Sept. de 2020

Respuestas (1)

Steven Lord
Steven Lord el 29 de Sept. de 2020
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 comentarios
Steven Lord
Steven Lord el 29 de Sept. de 2020
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)
Muhammad Sam'an
Muhammad Sam'an el 29 de Sept. de 2020
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

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by