不要在矩阵的小数点后显示零

编程入门 行业动态 更新时间:2024-10-24 04:35:27
本文介绍了不要在矩阵的小数点后显示零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试从以下矩阵A的第一行中删除小数点后的零.

I'm trying to remove the trailing zeros, after the decimal point, from the first row of the following matrix A.

A1 = [130: -20: 10] A2 = [1: 11/6: 12] A3 = [1/2: 1/4: 2]*pi A = [A1; A2; A3]

显示为:

A = 130.0000 110.0000 90.0000 70.0000 50.0000 30.0000 10.0000 1.0000 2.8333 4.6667 6.5000 8.3333 10.1667 12.0000 1.5708 2.3562 3.1416 3.9270 4.7124 5.4978 6.2832

最终矩阵必须是这样的:

The final matrix has to be like this one:

我该怎么做?

推荐答案

A1 = [130: -20: 10]; A2 = [1: 11/6: 12]; A3 = [1/2: 1/4: 2]*pi; format shortG % Where the magic happens A = [A1; A2; A3] A = 130 110 90 70 50 30 10 1 2.8333 4.6667 6.5 8.3333 10.167 12 1.5708 2.3562 3.1416 3.927 4.7124 5.4978 6.2832

只需使用format shortG.从技术上讲,零仅是数字精度的东西.有关所有显示样式,请查看format 上的文档.

Just use format shortG. The zeros are there technically only as a numerical accuracy-thing. Check the documentation on format for all display styles.

更多推荐

不要在矩阵的小数点后显示零

本文发布于:2023-10-14 22:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492403.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:小数点   矩阵   不要在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!