xxsimGetPlotIDFromName

PURPOSE ^

xxsimGetPlotIDFromName - Find the corresponding plot ID for a certain window and plot name.

SYNOPSIS ^

function retval = xxsimGetPlotIDFromName(windowName, plotName)

DESCRIPTION ^

 xxsimGetPlotIDFromName - Find the corresponding plot ID for a certain window and plot name.

 Syntax: 
   retval = xxsimGetPlotIDFromName(windowName, plotName)

 Inputs:
   windowName = Either the window name or the window ID.
   plotName   = Either the plot name or the plot ID.
 
 Outputs: 
   retval = returns the ID of the plot or -1 if the plot could not be found. If a number was inserted for plotName,
            this number is given as return value.
 
 Examples:
   retval = xxsimGetPlotIDFromName('Window 1', 'Motor Torque')
   
     - retval now contains the ID of the corresponding plot or -1 if the plot window does not exist.
     - if the input would be numeric, retval will get that numeric value.
     - Note: The simulator should be open before calling this function.  

 See also: xxsimGetPlotWindowIDFromName, xxsimGetPlotsFromWindow

 Author: Controllab Products B.V.
 email: info@controllab.nl
 Website: http://www.controllab.nl
 November 2015

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function retval = xxsimGetPlotIDFromName(windowName, plotName)
0002 % xxsimGetPlotIDFromName - Find the corresponding plot ID for a certain window and plot name.
0003 %
0004 % Syntax:
0005 %   retval = xxsimGetPlotIDFromName(windowName, plotName)
0006 %
0007 % Inputs:
0008 %   windowName = Either the window name or the window ID.
0009 %   plotName   = Either the plot name or the plot ID.
0010 %
0011 % Outputs:
0012 %   retval = returns the ID of the plot or -1 if the plot could not be found. If a number was inserted for plotName,
0013 %            this number is given as return value.
0014 %
0015 % Examples:
0016 %   retval = xxsimGetPlotIDFromName('Window 1', 'Motor Torque')
0017 %
0018 %     - retval now contains the ID of the corresponding plot or -1 if the plot window does not exist.
0019 %     - if the input would be numeric, retval will get that numeric value.
0020 %     - Note: The simulator should be open before calling this function.
0021 %
0022 % See also: xxsimGetPlotWindowIDFromName, xxsimGetPlotsFromWindow
0023 %
0024 % Author: Controllab Products B.V.
0025 % email: info@controllab.nl
0026 % Website: http://www.controllab.nl
0027 % November 2015
0028 
0029 %------------- BEGIN CODE --------------
0030 
0031   % Check the obtained amount of input arguments.
0032   if(nargin>2)
0033     error('Too many input arguments were specified.');
0034   elseif(nargin<2)
0035     error('Too little input arguments were specified.');
0036   end;
0037   
0038   % Get the window ID
0039   windowID = xxsimGetPlotWindowIDFromName(windowName);
0040   
0041   % Validate the window ID
0042   if(windowID == -1)
0043     error('Could not find the specified plot window.');
0044   end;
0045 
0046   % Get the plot ID, either via the name of the plot or directly the ID
0047   plotID = -1;
0048   % If the input is a string, interpret it as the name of the plot
0049   if(ischar(plotName))
0050     plotStruct = xxsimGetPlotsFromWindow(windowID); % Get all ID and name pairs of all plots.
0051     nameCount = 0;
0052     for i=1:length(plotStruct)
0053       if(strcmp(plotStruct(i).plotName,plotName))
0054         nameCount = nameCount + 1;
0055         if(nameCount == 1)
0056           plotID = plotStruct(i).plotID; % There is a window found with the given name, and its ID is stored.
0057         elseif(nameCount == 2)
0058           warning('Multiple plots found with the specified name. Selected the first plot.');
0059           break;
0060         end;
0061       end;
0062     end;
0063   % If the input is a number, then it is interpreted as the ID directly.
0064   elseif(isnumeric(plotName))
0065     plotID = plotName;
0066   % If the input is not numeric nor a string, give an error.
0067   else
0068     error('The specified plot name is not a string nor a number.');
0069   end;
0070   
0071   retval = plotID;
0072   
0073 end
0074 %------------- END OF CODE --------------

Generated on Sun 10-Dec-2017 19:24:51