Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference in Order of columns within matrix in Matlab

Tags:

matrix

matlab

I have got the following output of the two columns of a matrix:

final_matrix2 =

    0.0054    0.0000
    0.0051    0.0000
    0.0047    0.0000
    0.0042    0.0000
    0.0056    0.0000
    0.0034    0.0000
    0.0059    0.0000

The second column consists of zeros as it is of the order 1e-9 or 1e-10 or even lower.

I assume that these zeros appear due to the difference in magnitude (order) between the elements in two columns.

Is there a way to show correctly the elements in both columns within the same matrix?

like image 706
user131983 Avatar asked Oct 21 '22 13:10

user131983


1 Answers

First I simulate your problem . .

>> finalMatrix = randn(5,2)

finalMatrix =

   -1.3499   -0.2050
    3.0349   -0.1241
    0.7254    1.4897
   -0.0631    1.4090
    0.7147    1.4172

>> finalMatrix(:,2) = finalMatrix(:,2)*1e-20

finalMatrix =

   -1.3499   -0.0000
    3.0349   -0.0000
    0.7254    0.0000
   -0.0631    0.0000
    0.7147    0.0000

Then use the format command to show the missing precision (longG format works best for your specific issue) . .

    >> format longG
    >> finalMatrix

    finalMatrix =

             -1.34988694015652     -2.04966058299775e-21
              3.03492346633185     -1.24144348216312e-21
             0.725404224946106      1.48969760778546e-20
           -0.0630548731896562      1.40903448980048e-20
             0.714742903826096      1.41719241342961e-20

    >> 
like image 101
learnvst Avatar answered Oct 27 '22 10:10

learnvst