Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #12788 > unrolled thread

silly question on formatting tables

Started byalba.maydeu@gmail.com
First post2012-12-14 07:59 +0000
Last post2012-12-16 06:06 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  silly question on formatting tables alba.maydeu@gmail.com - 2012-12-14 07:59 +0000
    Re: silly question on formatting tables Peter Breitfeld <phbrf@t-online.de> - 2012-12-15 10:47 +0000
    Re: silly question on formatting tables Ray Koopman <koopman@sfu.ca> - 2012-12-16 06:06 +0000

#12788 — silly question on formatting tables

Fromalba.maydeu@gmail.com
Date2012-12-14 07:59 +0000
Subjectsilly question on formatting tables
Message-ID<kaem93$5qp$1@smc.vnet.net>
Dear all,

Consider the matrix

{{0, 0, 1.19092}, {0.883038, 0, 0.366804}, {0, 0, 0}}

How can I display it in matrixform/tableform so that the integers are displayed as integers and the reals are displayed only with 2 decimals?

If I use MatrixForm, the reals are displayed with 6 decimals, and if I use TableForm all numbers, including integers are displayed with 2 decimals. 

Thanks!

[toc] | [next] | [standalone]


#12806

FromPeter Breitfeld <phbrf@t-online.de>
Date2012-12-15 10:47 +0000
Message-ID<kahkgh$d75$1@smc.vnet.net>
In reply to#12788
Maybe this will help:

dgMF[x_] :=
 Map[If[Head[#] === Real, NumberForm[#, {20, 2}], #] &, x, {2}] // 
  MatrixForm

mat = {{0, 0, 1.19092}, {0.883038, 0, 0.366804}, {0, 0, 0}};
dgMF[mat]  
-- 
_________________________________________________________________
Peter Breitfeld | Bad Saulgau, Germany | http://www.pBreitfeld.de

[toc] | [prev] | [next] | [standalone]


#12810

FromRay Koopman <koopman@sfu.ca>
Date2012-12-16 06:06 +0000
Message-ID<kajodj$im0$1@smc.vnet.net>
In reply to#12788
On Dec 13, 11:59 pm, alba.may...@gmail.com wrote:
> Dear all,
>
> Consider the matrix
>
> {{0, 0, 1.19092}, {0.883038, 0, 0.366804}, {0, 0, 0}}
>
> How can I display it in matrixform/tableform so that the integers are displayed as integers and the reals are displayed only with 2 decimals?
>
> If I use MatrixForm, the reals are displayed with 6 decimals, and if I use TableForm all numbers, including integers are displayed with 2 decimals.
>
> Thanks!

mat = {{0, 0, 1.19092}, {0.883038, 0, 0.366804}, {0, 0, 0}};

Map[NumberForm[#,If[IntegerQ@#,3,{3,2}]]&,mat,{2}] //TableForm

0      0   1.19
0.88   0   0.37
0      0   0

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web