📄 evalsig.m
字号:
% Evaluate expression, invoking signal names from structure x.% Usage: y = evalsig(x, expr)% Note that numeric node names should be prepended by '@' to% distinguish them from constants. If the global variable% 'sweep' exists and is non-zero, a single curve is selected% from multiple SPICE parameter sweeps. Setting sweep=0% returns data for all sweeps.%% Written by Mike Perrott % Sweep selection added by Scott Willinghamfunction [y] = evalsig(x,expr)global sweep; % selects just one curve of data set%% replace ^ with .^, * with .*, / with ./ %% unless they are already preceeded by .expr = strrep(expr,'.^','^');expr = strrep(expr,'.*','*');expr = strrep(expr,'./','/');expr = strrep(expr,'^','.^');expr = strrep(expr,'*','.*');expr = strrep(expr,'/','./');%% parse expressiondelim = '+-/*^().:, ';delim_m = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789@';for j = 1:length(expr) if (expr(j) ~= ' ' & expr(j) ~= '-' & expr(j) ~= '(' & expr(j) ~= '+') break; endendif (j > 1) beginning = cellstr(expr(1:(j-1)));else beginning = ' ';endi = 1;r = expr(j:length(expr));while(1) if length(r) > 0 [t,r] = strtok(r,delim); if length(t) > 0 c(i) = cellstr(t); end i = i+1; [t,r] = strtok(r,delim_m); if length(t) > 0 c(i) = cellstr(t); end i=i+1; else break; endend%% prepend all node names that are pure numbers with @for i=1:length(x) temp_string = x(i).name; if sum(isletter(temp_string)) == 0 x(i).name = strcat('@',x(i).name); endend%% substitute structure names for spice signals namesfor i = 1:length(x) match_vec = strmatch(x(i).name,c,'exact'); if length(match_vec) > 0 for k=1:length(match_vec) if match_vec(k) < length(c) if strncmp(c(match_vec(k)+1),'(',1) ~= 1 %%avoid subst of functions szdata = size(x(i).data); if sweep > 0 & sweep <= szdata(2) c(match_vec(k))=cellstr(sprintf('x(%d).data(:,%d)',i,sweep)); else c(match_vec(k))=cellstr(sprintf('x(%d).data',i)); end end else szdata = size(x(i).data); if sweep > 0 & sweep <= szdata(2) c(match_vec(k))=cellstr(sprintf('x(%d).data(:,%d)',i,sweep)); else c(match_vec(k))=cellstr(sprintf('x(%d).data',i)); end end end endend%% convert to stringpexp='';for i=1:length(c) pexp = strcat(pexp,c(i));endpexp = strcat(beginning,pexp);%% evaluate expressiony = eval(char(pexp));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -