1
MATLAB給了我一個警告如下:警告:錯誤更新文本
Warning: Error updating Text.
Character vector must have valid interpreter syntax:
$\Theta(s) = 9.24\cdot 10^{04 }\cdot \frac{s + 0}{s^{4} + 140s^{3} + 2.35\cdot 10^{03s}^{2} + 9.24\cdot 10^{04s} + 0}$
我不知道爲什麼它是無效的語法。我使用下面的代碼:
numericTF = struct;
symbolTF = struct;
if strcmp(vars.response_type,'Position')
typeString = 'Theta(s)';
else
typeString = 'Omega(s)';
end
tf4thOnum = [1 I/P];
tf4thOden = [1 (b*L+R*J)/J/L (R*b+ Kb*Km)/J/L 2*Km*P/J/L I*2*Km/J/L];
tf4thOgain = 2*Km*P/J/L;
tf4thOstr = sprintf('$\\%s = %4.3g \\cdot \\frac{s + %4.3g}{s^{4} + %4.3gs^{3} + %4.3gs^{2} + %4.3gs + %4.3g}$', typeString, tf4thOgain,tf4thOnum(2:end),tf4thOden(2:end));
tf4thOsym = '\frac{k_ak_mk_p}{JL}\cdot\frac{s+\frac{k_i}{k_p}}{s^4+\frac{bL+RJ}{JL}s^3+\frac{bR+k_bk_m}{JL}s^2+\frac{k_ak_mk_p}{JL}s+\frac{k_ik_mk_ap}{JL}}$';
另一個功能添加科學記數法:
function instring = cleanExps(instring)
exps = findstr(instring,'e+');
maxn = length(exps);
if ~isempty(exps)
for ii = 1:maxn
if isempty(exps) break; end
instring = strrep(instring,instring(exps(1):exps(1)+4),['\cdot 10^{' instring(exps(1)+2:exps(1)+4) '}']);
exps = findstr(instring,'e+');
end
end
exps = findstr(instring,'e-');
maxn = length(exps);
if ~isempty(exps)
for ii = 1:maxn
if isempty(exps) break; end
instring = strrep(instring,instring(exps(1):exps(1)+4),['\cdot 10^{-' instring(exps(1)+2:exps(1)+4) '}']);
exps = findstr(instring,'e-');
end
end
這是非常有用的!但是,我認爲tf4thOstr格式正確?問題可能是字符串和數字之間的轉換? –
我添加了顯示方程的科學記數法的代碼。這可能是問題所在。 –
@DavidLing:是的,你的'cleanExps'函數有一個錯誤。修復了更新後的答案。 – gnovice