Error in sym: Character vectors and strings in the first argument can only specify a variable or num

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)')
  • 9
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cuntou0906

玛莎拉蒂是我的目标!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值