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