


xxsimSavePlotAsBitmap - Save a plot or plot window as bitmap. Supported formats: png, bmp, jpg, gif.
Syntax:
result = xxsimSavePlotAsBitmap(fileName, window, plot, width, height, dpi)
Inputs:
fileName = Path to where the bitmap should be stored. Supported file extensions: .png, .bmp, .jpg, .gif.
window = The name or ID of the plot window to select. negative => make plots of all plot window separately.
plot = (Optional) The plot (either via name or ID) to save. negative => plot all plots in window (default).
width = (Optional) The preferred width of the plot in pixels. 0 or negative => use same size as the plot (default).
height = (Optional) The preferred height of the plot in pixels. 0 or negative => use same size as the plot (default).
dpi = (Optional) The dpi the bitmap should be stored in. 0 or negative => use the resolution of the screen (default).
Outputs:
result = returns true when the plot was saved successfully.
Examples:
result = xxsimSavePlotAsBitmap('Demo.png','Plots');
Save the plot window called "Plots" as a PNG plot in the current directory with name Demo.png.
result = xxsimSavePlotAsBitmap('Demo.png','Plots','Voltage');
Save the plot "Voltage" in window "Plots" as a PNG plot in the current directory with name Demo.png.
result = xxsimSavePlotAsBitmap('Demo.png','Plots','Voltage',1200,900,300);
Save the plot "Voltage" in window "Plots" as a PNG plot with width of 1200 pixels, height of 900 pixels, and dpi of 300 in the current directory with name Demo.png.
result = xxsimSavePlotAsBitmap('Demo.png',-1);
Save all plot windows in the active model as PNG plots with names Demoxx.png, in which xx indicates the plot window number in the tree in the simulator.
Author: Controllab Products B.V.
email: info@controllab.nl
Website: http://www.controllab.nl
November 2015

0001 function result = xxsimSavePlotAsBitmap(fileName, window, varargin) 0002 % xxsimSavePlotAsBitmap - Save a plot or plot window as bitmap. Supported formats: png, bmp, jpg, gif. 0003 % 0004 % Syntax: 0005 % result = xxsimSavePlotAsBitmap(fileName, window, plot, width, height, dpi) 0006 % 0007 % Inputs: 0008 % fileName = Path to where the bitmap should be stored. Supported file extensions: .png, .bmp, .jpg, .gif. 0009 % window = The name or ID of the plot window to select. negative => make plots of all plot window separately. 0010 % plot = (Optional) The plot (either via name or ID) to save. negative => plot all plots in window (default). 0011 % width = (Optional) The preferred width of the plot in pixels. 0 or negative => use same size as the plot (default). 0012 % height = (Optional) The preferred height of the plot in pixels. 0 or negative => use same size as the plot (default). 0013 % dpi = (Optional) The dpi the bitmap should be stored in. 0 or negative => use the resolution of the screen (default). 0014 % 0015 % Outputs: 0016 % result = returns true when the plot was saved successfully. 0017 % 0018 % Examples: 0019 % result = xxsimSavePlotAsBitmap('Demo.png','Plots'); 0020 % Save the plot window called "Plots" as a PNG plot in the current directory with name Demo.png. 0021 % 0022 % result = xxsimSavePlotAsBitmap('Demo.png','Plots','Voltage'); 0023 % Save the plot "Voltage" in window "Plots" as a PNG plot in the current directory with name Demo.png. 0024 % 0025 % result = xxsimSavePlotAsBitmap('Demo.png','Plots','Voltage',1200,900,300); 0026 % Save the plot "Voltage" in window "Plots" as a PNG plot with width of 1200 pixels, height of 900 pixels, and dpi of 300 in the current directory with name Demo.png. 0027 % 0028 % result = xxsimSavePlotAsBitmap('Demo.png',-1); 0029 % Save all plot windows in the active model as PNG plots with names Demoxx.png, in which xx indicates the plot window number in the tree in the simulator. 0030 % 0031 % Author: Controllab Products B.V. 0032 % email: info@controllab.nl 0033 % Website: http://www.controllab.nl 0034 % November 2015 0035 0036 %------------- BEGIN CODE -------------- 0037 plotID = -1; 0038 height = -1; 0039 width = -1; 0040 dpi = -1; 0041 0042 % There cannot be more than 4 variable input arguments. 0043 if length(varargin)> 4 0044 error('Too many input arguments.'); 0045 end 0046 0047 % At least two input arguments have to be specified. 0048 if nargin < 2 0049 error('Too little input arguments.'); 0050 end 0051 0052 % fileName: first argument should be a string 0053 if ~ischar(fileName) 0054 error('fileName should be a string'); 0055 end 0056 0057 % translate the filename into something that 20-sim can understand 0058 % check if the user provided a full name 0059 [directory, name, extension] = fileparts(fileName); 0060 if isempty(directory) 0061 % use the current directory 0062 directory = pwd; 0063 else 0064 % make it an absolute path 0065 currentDir = pwd; 0066 cd(directory); 0067 directory = pwd; 0068 cd(currentDir); 0069 end 0070 useFileName = fullfile(directory, [name, extension]); 0071 0072 % window: second argument should be a string or number 0073 if (~ischar(window) && ~isnumeric(window)) 0074 error('window should be a string or number'); 0075 end 0076 0077 % Acquire the window ID via the name of the window. 0078 windowID = xxsimGetPlotWindowIDFromName(window); 0079 0080 if length(varargin) >= 1 0081 % plot: third argument should be a string or number, if defined at all. 0082 if (~ischar(varargin{1}) && ~isnumeric(varargin{1})) 0083 error('plot should be a string or number'); 0084 end 0085 0086 % Acquire the plot ID via the name of the plot. 0087 plotID = xxsimGetPlotIDFromName(windowID,varargin{1}); 0088 0089 % Warn the user when only a height is specified. 0090 if length(varargin) == 2 0091 warning('No height is specified for the given width, automatic scaling will be used.'); 0092 end 0093 0094 % Do the check for if a height and width is specified. 0095 if length(varargin) >= 3 0096 0097 % Check if the height and width are numeric. 0098 if(~isnumeric(varargin{2})) 0099 error('width should be a number'); 0100 end 0101 if(~isnumeric(varargin{3})) 0102 error('height should be a number'); 0103 end 0104 0105 % Set height 0106 if varargin{2} > 0 0107 width = varargin{2}; 0108 end 0109 % Set width 0110 if varargin{3} > 0 0111 height = varargin{3}; 0112 end 0113 0114 % Check if there is a dpi input 0115 if(length(varargin) >= 4) 0116 % Check if the dpi input is a number. 0117 if(~isnumeric(varargin{4})) 0118 error('dpi should be a number'); 0119 end 0120 0121 % Set dpi 0122 if varargin{4} > 0 0123 dpi = varargin{4}; 0124 end 0125 end 0126 end 0127 end 0128 0129 % invoke 20-sim with the xmlrpc call 0130 inputs = struct('fileName', useFileName, 'windowID', int32(windowID), 'plotID', int32(plotID), 'width', int32(width), 'height', int32(height), 'dpi', int32(dpi)); 0131 result = xrlinvoke('xxsim.plot.savePlotAsBitmap', inputs); 0132 end 0133 %------------- END CODE --------------