我是靠谱客的博主 友好往事,最近开发中收集的这篇文章主要介绍Error in sym: Character vectors and strings in the first argument can only specify a variable or numMATLAB报错:Error in sym: Character vectors and strings in the first argument can only specify a variable or number.,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
MATLAB报错:Error in sym: Character vectors and strings in the first argument can only specify a variable or number.
问题
错误使用 sym>convertChar (line 1459)
Character vectors and strings in the first argument can only specify a
variable or number. To evaluate character vectors and strings
representing symbolic expressions, use 'str2sym'.
出错 sym>tomupad (line 1225)
S = convertChar(x);
出错 sym (line 214)
S.s = tomupad(x);
出错 sym/subs>@(x)sym(x) (line 209)
Y = cellfun(@(x)sym(x),Y,'UniformOutput',false);
出错 sym/subs>normalize (line 209)
Y = cellfun(@(x)sym(x),Y,'UniformOutput',false);
出错 sym/subs>mupadsubs (line 157)
[X2,Y2,symX,symY] = normalize(X,Y); %#ok
出错 sym/subs (line 145)
G = mupadsubs(F,X,Y);
出错 robotfish_model_DL_DL (line 567)
xtemp(i)=subs(xtemp(i),{x,y,theta,fai,d_x,d_y,d_theta,d_fai},{'X(1)','X(2)','X(3)','X(4)','X(5)','X(6)','X(7)','X(8)'});
出错 main_DL_DL (line 27)
robotfish_model_DL_DL(1); % 生成模型
解决
在matlab
高一点的版本(如R2018b
),是严格区分符号sym
和字符串str
的,因此需要注意使用str2sym()
或者sym2str()
转换。
例如,subs()
函数中可以替换符号语句中的符号变量,但新一点的版本只支持符号变量或者符号语句替,不能用字符串,因此换需要做一个转换:
新版本(R2018b
以上):
%%% temp是一个符号语句,x是符号变量
subs(temp,x,str2sym('X(1)'))
老版本:
%%% temp是一个符号语句,x是符号变量
subs(temp,x,'X(1)')
最后
以上就是友好往事为你收集整理的Error in sym: Character vectors and strings in the first argument can only specify a variable or numMATLAB报错:Error in sym: Character vectors and strings in the first argument can only specify a variable or number.的全部内容,希望文章能够帮你解决Error in sym: Character vectors and strings in the first argument can only specify a variable or numMATLAB报错:Error in sym: Character vectors and strings in the first argument can only specify a variable or number.所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复