MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   MATLAB:???类型为'char'的输入参数的未定义函数或方法'sprint' (https://www.labfans.com/bbs/showthread.php?t=24152)

poster 2019-12-10 20:48

MATLAB:???类型为'char'的输入参数的未定义函数或方法'sprint'
 
我试图显示结果的小数点后16位。我输入的代码是这样

clear x; x = 0.245; 1-x+1/2*x.^2-1/6*x.^3+1/24*x.^4 sprint('%0.16f', ans) Matlab给我这个答案

ans = 0.7827 ??? Undefined function or method 'sprint' for input arguments of type 'char'. 我有两个问题:
[LIST=1][*]发生什么事?我想我以前用过它,并且“ sprintf”没有问题,可以显示小数点后一位的结果。[*]如何显示更多小数位?[/LIST]谢谢!



[B]回答:[/B]

sprintf数据格式化为字符串;它不显示输出。此外,它是sprintf ,而不是sprint ,这是您键入的功能,而MATLAB一直在抱怨。 (它不知道什么是sprint ,但是它知道sprintf 。)

如果您打算将ans保存为一个字符串,保留为小数点后16位数字,请使用sprintf 。要只显示它(我认为是您想要的),请使用printf 。无论哪种情况,问题都是显而易见的。您忘记了sprintf的f !



[url=https://stackoverflow.com/questions/4269276]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 01:04

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.