% % MATLAB script for visualization of scalar field data % Latest update: 2014.1.10 % % ---------- How to execute ---------- % >> run('visualize_scalarfield3d') % ------------------------------------ % function visualize_scalarfield3d() fid=fopen('scalar_field_3d.dat','rb'); data = fread(fid,[4,inf],'double'); % ========== definition of uniform grid ========== xmax = 5.0; ymax = 5.0; zmax = 5.0; xmin = 0.0; ymin = 0.0; zmin = 0.0; dx = 0.1; [xq yq zq] = meshgrid(xmin:dx:xmax,ymin:dx:ymax,zmin:dx:zmax); % ================================================ % ========== read data ========== % % data(1,:) = x, data(2,:) = y, data(3,:) = z, data(4,:) = f(x,y,z) % vq = griddata3(data(1,:),data(2,:),data(3,:),data(4,:),xq,yq,zq); mx = (xmax-xmin)/2.0; my = (ymax-ymin)/2.0; mz = (zmax-zmin)/2.0; h = slice(xq,yq,zq,vq,[mx],[my],[mz]); % =============================== % ----- draw colormap ----- set(h,'EdgeColor','none'); alpha('color') alphamap('increase',.3) % ------------------------- axis([xmin xmax ymin ymax zmin zmax]); ylabel('y', ... 'FontWeight','b','Color','b', ... 'VerticalAlignment','bottom'); % boldface blue xlabel('x', ... 'FontWeight','b','Color','b', ... 'VerticalAlignment','bottom'); % boldface blue zlabel('z', ... 'FontWeight','b','Color','b', ... 'VerticalAlignment','bottom'); % boldface blue colorbar % colorbar on the right side fclose(fid); end