function sparse_grid_display ( input_file_name, rmin, rmax ) %% SPARSE_GRID_DISPLAY displays a 2D or 3D sparse grid. % % Modified: % % 22 April 2007 % % Author: % % John Burkardt % fprintf ( 1, '\n' ); timestamp; fprintf ( 1, '\n' ); fprintf ( 1, 'SPARSE_GRID_DISPLAY:\n' ); fprintf ( 1, ' MATLAB version\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' Display a 2D or 3D sparse grid.\n' ); % % First command line argument is the file name. % if ( nargin < 1 ) fprintf ( 1, '\n' ); fprintf ( 1, 'SPARSE_GRID_DISPLAY:\n' ); input_file_name = input ( 'Enter the name of the file containing the points:' ); end % % Second command line argument is the lower range. % if ( nargin < 2 ) fprintf ( 1, '\n' ); fprintf ( 1, 'SPARSE_GRID_DISPLAY:\n' ); rmin = input ( 'Enter the minimum value of the range:' ); end % % Third command line argument is the upper range. % if ( nargin < 3 ) fprintf ( 1, '\n' ); fprintf ( 1, 'SPARSE_GRID_DISPLAY:\n' ); rmax = input ( 'Enter the maximum value of the range:' ); end % % Load the data. % points = load ( input_file_name )'; dim_num = size ( points, 1 ); point_num = size ( points, 2 ); % % 2D Plot % if ( dim_num == 2 ) % % Clear the graphics frame; % clf % % We have to name the axes in order to control the grid. % axes_handle = axes; % % Plot the points. % handle = scatter ( points(1,:), points(2,:), 'b', 'filled' ); % % Force the plotting region to be square, not rectangular. % axis square % % Request grid lines. % grid on % % Specify the location of the grid lines, and suppress labeling. % rdelt = ( rmax - rmin ) / 8.0; ticks = rmin : rdelt : rmax; set ( axes_handle, 'xtick', ticks ); set ( axes_handle, 'xticklabel', [] ); set ( axes_handle, 'ytick', ticks ); set ( axes_handle, 'yticklabel', [] ); % % Make the plotting region slightly bigger than the data. % range = rmax - rmin; rmin1 = rmin - 0.05 * range; rmax1 = rmax + 0.05 * range; axis ( [ rmin1, rmax1, rmin1, rmax1 ] ) xlabel ( '--X axis--' ) ylabel ( '--Y axis--' ) % % Title % title_string = s_escape_tex ( input_file_name ); title ( title_string ); % % Make an output file name based on the input file name, but % with "PNG" extension. % output_file_name = file_name_ext_swap ( input_file_name, 'png' ); % % Save the figure and write it out. % frame = getframe; [ image, map ] = frame2im ( frame ); imwrite ( image, output_file_name, 'PNG' ); fprintf ( 1, '\n' ); fprintf ( 1, 'SPARSE_GRID_DISPLAY\n' ); fprintf ( 1, ' The input data "%s" was read in, and plotted\n', ... input_file_name ); fprintf ( 1, ' in the PNG file "%s".\n', output_file_name ); % % 3D plot % elseif ( dim_num == 3 ) % % Clear the graphics frame; % clf % % We have to name the axes in order to control the grid. % axes_handle = axes; % % Plot the points. % handle = scatter3 ( points(1,:), points(2,:), points(3,:), 'b', 'filled' ); % % Force the plotting region to be square, not rectangular. % axis square % % Request grid lines. % grid on % % Specify the location of the grid lines, and suppress labeling. % rdelt = ( rmax - rmin ) / 8.0; ticks = rmin : rdelt : rmax; set ( axes_handle, 'xtick', ticks ); set ( axes_handle, 'xticklabel', [] ); set ( axes_handle, 'ytick', ticks ); set ( axes_handle, 'yticklabel', [] ); set ( axes_handle, 'ztick', ticks ); set ( axes_handle, 'zticklabel', [] ); % % Make the plotting region slightly bigger than the data. % range = rmax - rmin; rmin1 = rmin - 0.05 * range; rmax1 = rmax + 0.05 * range; axis ( [ rmin1, rmax1, rmin1, rmax1 ] ) xlabel ( '--X axis--' ) ylabel ( '--Y axis--' ) zlabel ( '--Z axis--' ) % % Title % title_string = s_escape_tex ( input_file_name ); title ( title_string ); view ( -10, 15 ) % % Make an output file name based on the input file name, but % with "PNG" extension. % output_file_name = file_name_ext_swap ( input_file_name, 'png' ); % % Save the figure and write it out. % frame = getframe; [ image, map ] = frame2im ( frame ); imwrite ( image, output_file_name, 'PNG' ); fprintf ( 1, '\n' ); fprintf ( 1, 'SPARSE_GRID_DISPLAY\n' ); fprintf ( 1, ' The input data "%s" was read in, and plotted\n', ... input_file_name ); fprintf ( 1, ' in the PNG file "%s".\n', output_file_name ); end % % Terminate. % fprintf ( 1, '\n' ); fprintf ( 1, 'SPARSE_GRID_DISPLAY:\n' ); fprintf ( 1, ' Normal end of execution.\n' ); fprintf ( 1, '\n' ); timestamp;