MATLAB:???未定义的函数或方法“sprint”;对于“char”类型的输入参数

发布于 2024-10-05 00:05:06 字数 398 浏览 1 评论 0原文

我试图显示结果的小数点后 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'.

我有两个问题:

  1. 发生了什么?我想我以前使用过它,并且使用“sprintf”显示带有几个小数位的结果没有任何问题。
  2. 我该怎么做才能显示更多小数位?

谢谢你!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

输什么也不输骨气 2024-10-12 00:05:06

sprintf 将数据格式化为字符串;它不会显示它以进行输出。此外,它是 sprintf,而不是 sprint,后者是您键入的函数,而 MATLAB 正在抱怨该函数。 (它不知道 sprint 是什么,但它知道 sprintf。)

如果要将 ans 作为保留 16 位小数的数字保存到字符串中,请使用 <代码>sprintf。要仅显示它(我认为这就是您想要的),请改用 printf 。无论哪种情况,问题都很清楚;您忘记了 sprintf 中的 f

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!

陪你到最终 2024-10-12 00:05:06

好吧,我认为“vpa”这可以帮助我显示更多小数位

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)

编辑:
这是 matlab 的答案:

expresion =

0.7827


ans =

.7827116041927082

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
无畏 2024-10-12 00:05:06

我认为您之前没有使用过sprint。 MATLAB 没有名为 sprint 的内部函数,您应该使用 sprintf

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文