melisa zand
melisa zand

Reputation: 211

matlab: change matrix

I have a code that load cell array and convert them to matrix. now this matrix shows 4 numbers after floating point for example

0   5   15  1   51,9000 3,4000
0   5   15  1   51,9000 3,4000
0   5   15  1   51,9000 3,4000

how can I change all af the rows to just show 2 numbers after the floating point ? please consider that I want to change the matrix not print it in command window !

Upvotes: 2

Views: 371

Answers (2)

Andrey Rubshtein
Andrey Rubshtein

Reputation: 20915

If you want to see it in the command window/editor for debugging purposes, use bank format:

format bank;

Example:

A =[ 51.213123 6.132434]
format bank
disp(A);

Will result in :

A =    
         51.21          6.13

Also, you can use sprintf

A = [51.900 3.4000];
disp(sprintf('%2.2f ',A));

Upvotes: 1

petrichor
petrichor

Reputation: 6569

x = [0   5   15  1   51.9000 3.4000
     0   5   15  1   51.9000 3.4000
     0   5   15  1   51.9000 3.4000];

fprintf([repmat('%.2f ',1,size(x,2)) '\n'], x')

0.00 5.00 15.00 1.00 51.90 3.40 
0.00 5.00 15.00 1.00 51.90 3.40 
0.00 5.00 15.00 1.00 51.90 3.40 

Upvotes: 0

Related Questions