Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Find out how long after division will be an integer?
조회 수: 1(최근 30일)
표시 이전 댓글
Hello! Is it possible to know when the condition will be met, what has been divided and the result is an integer?
A=[1:100];
for i=1:30
Ax(i)=A(i)/2;
if Ax(i) not a fractional number
Ax(i)=Ax(i);
else
break
end
end
댓글 수: 0
답변(2개)
KSSV
2020년 7월 28일
if mod(x,1)==0 then x is an whole number/ integer.
댓글 수: 2
KSSV
2020년 7월 29일
A=[1:100];
count = 0 ;
iwant = zeros([],1) ;
for i=1:30
Ax(i)=A(i)/2;
if ~mod(Ax(i),1) % Ax(i) not a fractional number
count = count+1 ;
iwant(count)=Ax(i);
end
end
iwant
You need not to use a loop.
idx = mod(Ax,1) ;
iwant = Ax(idx==0) ;
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!