不要在矩阵的小数点后显示零 [英] Do not display zeros after decimal point in a matrix

查看:101
本文介绍了不要在矩阵的小数点后显示零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从以下矩阵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.

这篇关于不要在矩阵的小数点后显示零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆