# I have to do matrix with 'single' vectors

1 view (last 30 days)
Valerio Gianforte on 4 Mar 2020
Answered: dpb on 4 Mar 2020
Hi everyone,
I done a matrix with 'single' vectors. The problem is that when I do the matrix, matlab changes the values of each vector. For example, the first column represents the years and when I insert the Years vector in the matrix the value changes from 1985 to 0.0198500, this for each column. I'm attacching my code and the matrix below. Is there a way to do a matrix without that matlab changes the values?
Data_table = table(time_date, time2, Hs_buoy, Tm_buoy, Dm_buoy);
HH = single(cell2mat(Data_table.time2(:,:)));
YYMMDD = vertcat(time_date{:});
Years = single(YYMMDD.Year);
Months = single(YYMMDD.Month);
Days = single(YYMMDD.Day);
Hs_tot = cell2mat(Data_table.Hs_buoy(:,:));
Tm_tot = cell2mat(Data_table.Tm_buoy(:,:));
Dm_tot = cell2mat(Data_table.Dm_buoy(:,:));
data_matrix = [Years Months Days HH Hs_tot Tm_tot Dm_tot];
and then the matrix:
data_matrix =
1472×7 single matrix
1.0e+05 *
0.0198500 0.0000100 0.0000100 0 0.0000088 0.0000426 0.0028428
0.0198500 0.0000100 0.0000100 0.6000000 0.0000073 0.0000370 0.0027256
0.0198500 0.0000100 0.0000100 1.2000000 0.0000072 0.0000359 0.0027142
0.0198500 0.0000100 0.0000100 1.8000000 0.0000062 0.0000360 0.0027929
0.0198500 0.0000100 0.0000200 0 0.0000039 0.0000345 0.0027787
0.0198500 0.0000100 0.0000200 0.6000000 0.0000027 0.0000305 0.0027401
0.0198500 0.0000100 0.0000200 1.2000000 0.0000027 0.0000247 0.0026128
0.0198500 0.0000100 0.0000200 1.8000000 0.0000030 0.0000262 0.0025042
0.0198500 0.0000100 0.0000300 0 0.0000031 0.0000269 0.0024614
0.0198500 0.0000100 0.0000300 0.6000000 0.0000032 0.0000271 0.0024086
0.0198500 0.0000100 0.0000300 1.2000000 0.0000050 0.0000291 0.0023772
0.0198500 0.0000100 0.0000300 1.8000000 0.0000047 0.0000325 0.0023501
0.0198500 0.0000100 0.0000400 0 0.0000039 0.0000314 0.0023373
0.0198500 0.0000100 0.0000400 0.6000000 0.0000037 0.0000297 0.0023687
0.0198500 0.0000100 0.0000400 1.2000000 0.0000045 0.0000297 0.0023972
0.0198500 0.0000100 0.0000400 1.8000000 0.0000051 0.0000331 0.0023486
0.0198500 0.0000100 0.0000500 0 0.0000047 0.0000336 0.0023129
Thank you so much.

Walter Roberson on 4 Mar 2020
Give the command
format long g
The content of the matrix is not changing, only the display of it is. Notice the
1.0e+05 *
which means that the values below that need to be multiplied by 1.0e+05 to understand the values that are stored.
That kind of output with a multiplier at the top is used with format short in order to support a more compact output with limited space.
Valerio Gianforte on 4 Mar 2020
Thank you so much :)

dpb on 4 Mar 2020
The values don't change, only the display format so you get something other than zero displayed for numbers smaller than the precision of the chosen field.
NB the "1.0e+05 *" at the top of the page -- if you multiply 0.01985 by 1E5, you have 1985, precisely the value you asked for.
Try
data_matrix(1:5,1)
at the command line to see.
The problem is you've asked to display the whole array at once and the difference in magnitude between various columns is such just can't do so well with a single format.
It would be nice if TMW would upgrade the smarts of the command window output routines to auto-scale columns of arrays, but it would cause a lot of overhead in the display processing in all likelihood to do so.

### Categories

Find more on Operating on Diagonal Matrices in Help Center and File Exchange

R2018b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!