필터 지우기
필터 지우기

Sorting Prime Numbers From an Array of Numbers, Into a New Array

조회 수: 7 (최근 30일)
Kevin Krone
Kevin Krone 2019년 9월 20일
댓글: David Hill 2019년 9월 20일
n = [1:1:100];
N = isprime(n);
NN=[];
for i = 1:1:100
if N(i)==1 %if N at a position is equal to 1, then it is a prime number
n(i) %Displays the integer at that position %Now that number needs to be stored in a new array
NN=n(i) %This just sets the new array equal to the prime number n(i), this doesn't store it. It is replaced on the next loop
end
end
I need to know how to make a new array filled with the prime numbers from the loop

채택된 답변

David Hill
David Hill 2019년 9월 20일
Why not use the primes function?
NN=primes(100);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by