a=[17,24,1,8,15,23,5,7,14,16]; fid = fopen('a.txt','wt'); for i=1:length(a) fprintf(fid,'a(%d)=%g\n',i,a(i));end fclose(fid);就可以到达你的效果。