gusucode.com > symbolic工具箱matlab源码程序 > symbolic/symReadSSCVariables.m
function [names,values,units]=symReadSSCVariables(componentName,varargin) %symReadSSCVariables Load variables from a Simscape component % [names,values,units] = symSSCReadVariables(componentName) returns the % names, values and units for all the variables from the given Simscape % component. % % names, values and units are each returned as a cell array of symbolic % objects where names{i}, values{i} and units{i} correspond. values{i} % and units{i} contain the value and the unit for the variable names{i}. % % componentName is the name of a Simscape component. % The component must be on the matlabpath or in the current directory, % otherwise it is not found. % % [names,v,u] = symReadSSCVariables(componentName,'ReturnFunctions',true) % returns for names a cell array of symbolic functions v(t) instead of % symbolic object v. % % See also symReadSSCVariables, symWriteSSC % Copyright 2015-2016 The MathWorks, Inc. narginchk(1,3); validateattributes(componentName, {'char'}, {'row'}); try variables = simscape.smt.variables(componentName); catch ME if isequal(ME.identifier, 'MATLAB:undefinedVarOrClass') error(message('symbolic:symSSC:SimscapeRequired')); elseif isequal(ME.identifier,'simscape:smt:DomainNotSupported') error(message('symbolic:symSSC:DomainsNotSupported')); else rethrow(ME); end end opts = getOptions(varargin); names = cell(1, length(variables)); if nargout > 1 values = cell(1, length(variables)); end if nargout > 2 units = cell(1, length(variables)); end for i = 1:length(variables) if opts.ReturnFunctions names{i} = symfun([variables(i).name '(t)'], sym('t')); else names{i} = sym(variables(i).name); end if nargout > 1 values{i} = sym(variables(i).value); end if nargout > 2 units{i} = feval(symengine, 'unit::convertUnits', ['"' variables(i).unit '"'], '#Simscape'); end end % parse inputs and return option structure output function opts = getOptions(args) ip = inputParser; ip.addParameter('ReturnFunctions', false, @(x) isequal(x,true) || isequal(x,false)); ip.parse(args{:}); opts = ip.Results;