create a list with primes between 1000 and 10000 in matlab

One possible solution in Matlab is:

main.m
primes = [];

for n=1000:10000
    if isprime(n)
        primes = [primes n];
    end
end
90 chars
8 lines

This will loop through all the numbers between 1000 and 10000, and if a number is prime, it will be added to the primes array.

Note that isprime is a built-in Matlab function that returns true if a given number is prime, and false otherwise.

related categories

gistlibby LogSnag