MATLAB:???类型为'char'的输入参数的未定义函数或方法'sprint' [英] MATLAB: ??? Undefined function or method 'sprint' for input arguments of type 'char'
问题描述
我试图显示结果的16位小数位。我输入的代码是
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给我这个答案
Matlab give me this answer
ans =
0.7827
??? Undefined function or method 'sprint' for input arguments of type 'char'.
我有两个问题:
- 会发生什么?
- 我可以做些什么来显示更多的小数位数?
谢谢!
推荐答案
sprintf
将数据格式化为字符串;它不显示它的输出。此外,它是 sprintf
,而不是 sprint
,这是您键入的函数 - 和MATLAB抱怨。 (它不知道 sprint
是什么,但它知道 sprintf
。)
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
.)
如果要将ans保存为一个16位小数的数字,请使用 sprintf
。要显示它,我认为是你想要的,请改用 printf
。在任何一种情况下,问题是明确的;您忘记了 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
!
这篇关于MATLAB:???类型为'char'的输入参数的未定义函数或方法'sprint'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!