필터 지우기
필터 지우기

Do not take any amount

조회 수: 1 (최근 30일)
lech king
lech king 2020년 10월 5일
댓글: lech king 2020년 10월 5일
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

채택된 답변

KSSV
KSSV 2020년 10월 5일
편집: KSSV 2020년 10월 5일
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
lech king
lech king 2020년 10월 5일
Thank you very much
This is it

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by