nx=120; ny=31; nz=29; nf=4; % covers u, v, w, and theta h=zeros(nf*nz*ny*nx,1); vectorsize=nx*ny*nz*nf; dim=1; % current dimension in loop obs=0; % observation counter fid = fopen('hfile.txt','w'); for i=1:nf for j=1:nz for k=1:ny for l=1:nx if ((any(j==[5 10 15 20 25]) & ... % 5 levels... any(i==[1 2]) & ... % of u and v... k>8 & ... % that clear the center... mod(l,3)==0 ) | ... % every third "spoke", plus... (i==4 & ... % theta... any(k==[9 30]))) % in the vert boundary layers h(dim)=dim; fprintf(fid,'%i\n',dim); obs=obs+1; end dim=dim+1; end end end end fclose(fid); obs h3=reshape(h,[nx,ny,nz,nf]);