开发者

MATLAB: ??? Undefined function or method 'sprint' for input arguments of type 'char'

I´m trying to show 16 decimal place of a result. The code I put is this

clear x;
x = 0.245;
1-x+1/2*x.^2-1/6*x.^3+1/24*x.^4
sprint('%0.1开发者_运维问答6f', ans)

Matlab give me this answer

ans =

0.7827

??? Undefined function or method 'sprint' for input arguments of type 'char'.

I have two question:

  1. What happen? I think I used it before and I had no problems with 'sprintf' for show a result with several decimal places.
  2. What can I do to show more decimal places?

Thank you!


sprintf formats data into a string; it does not display it for output. Furthermore, it's sprintf, not sprint, which is the function you've typed- and that MATLAB is complaining about. (It doesn't know what sprint is, but it knows about sprintf.)

If you mean to save ans to a string as a number to 16 decimal places, use sprintf. To just display it, which I think is what you want, use printf instead. In either case, the issue is clear; you forgot the f in sprintf!


Well, I think 'vpa' this help me to show more decimal places

clear x;
clear expresion;
x = 0.245;
expresion = 1-x+1/2*x.^2-1/6*x.^3+1/24*x.^4
%sprint('%0.16f', ans)
vpa(expresion,16)

EDIT: and this is the matlab answer:

expresion =

0.7827


ans =

.7827116041927082


I think you did not use sprint before. There is no MATLAB intrinsic function called sprint, you ought to use sprintf.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜