How to set a different display style for each matrix element?

I have a matrix:

G =

10.0000e+000     0.0000e+000     4.0000e+000     2.7013e-009
10.0000e+000    10.0000e+000     1.0000e+000     7.7550e-009
 5.0000e+000     5.0000e+000     2.0000e+000   -15.3223e-009
10.0000e+000    10.0000e+000     3.0000e+000     6.6898e-009

but I want to show it like this: only with specific numbers in scientific notation, is this possible:

G =

10     0     4     2.7013e-009
10    10     1     7.7550e-009
 5     5     2   -15.3223e-009
10    10     3     6.6898e-009

Matrix Code:

x_1=0;  y_1=0;   z_1=0; 
x_2=10; y_2=0;   z_2=4;
x_3=10; y_3=10;  z_3=1;
x_4=5;  y_4=5;   z_4=2;

cT21 =   2.701320e-09 
cT31 =   7.755042e-09 
cT41 =   -1.532233e-08 
cT51 =   6.689788e-09 

format shortEng
G = [x_2 y_2 z_2 cT21; x_3 y_3 z_3 cT31; x_4 y_4 z_4 cT41; x_5 y_5 z_5 cT51]
+4
source share
1 answer
fprintf('%i %i %i %e \n',G.')
10 0 4 2.701300e-09 
10 10 1 7.755000e-09 
5 5 2 -1.532230e-08 
10 10 3 6.689800e-09 

using fprintf. You choose %ifor each integer and %efor each exponent. /ntakes care of line breaks for each line contained in G. Pay attention to G.'; MATLAB is displayed in the main column order, so Gyou must first wrap it.

Even easier, choose format shortGone that automatically executes all the values ​​regardless of their place in the matrix:

format shortG
G =

           10            0            4   2.7013e-09
           10           10            1    7.755e-09
            5            5            2  -1.5322e-08
            5            5            2   6.6898e-09
+6

Source: https://habr.com/ru/post/1670793/


All Articles