Borrar filtros
Borrar filtros

Do not take any amount

1 visualización (últimos 30 días)
lech king
lech king el 5 de Oct. de 2020
Comentada: lech king el 5 de Oct. de 2020
pop=randi([100],20,8);
[r1,c1]=size(pop);
for i=1:r1
A=randi(100);
if A<=90
pool(i,:)=pop(i,:);
end
end
Hi
I want if the condition is not met, the pool variable does not take any value, in other words, in the end, for example, it becomes an 18x8 matrix, not an 20x8 matrix with 2 rows containing the value 0
Thank you for your guidance

Respuesta aceptada

KSSV
KSSV el 5 de Oct. de 2020
Editada: KSSV el 5 de Oct. de 2020
pop=randi([100],20,8);
[r1,c1]=size(pop);
pool = zeros([],c1) ;
count = 0 ;
for i=1:r1
A=randi(100);
if A<=90
count = count+1 ;
pool(count,:)=pop(i,:);
end
end
You need not to use loop...it can be vectorized.
pop=randi([100],20,8);
[r1,c1]=size(pop);
A = randi(100,1,r1) ;
pool = pop(A<=90,:) ;
  1 comentario
lech king
lech king el 5 de Oct. de 2020
Thank you very much
This is it

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by