简体   繁体   中英

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.16f', 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM