gusucode.com > 《精通matlab 7》包括配套光盘 > 配套光盘里的程序附件/Ex-10/Ex1001.m
%例10-1 脚本M文件实例 %Find the prime numbers between 10 and 1000 %clear the workspace clear %result save the prime numbers. result=[]; %for-loop for i=10:1000 %define a variable which is used to mark whether i is a prime number mark=1; %check whether i is a prime number for j=2:i-1 if mod(i,j)==0 mark=0; break end end %add prime number to result if mark==1 result=[result i]; end end %output result