concatenate repeating digit to the end of a column in numeric matrix

1 view (last 30 days)
I have a large numeric matrix that has truncated the 3rd decimal place. I would like to include the 3rd decimal place in the binDepth column. I am sure this is just a loop that I need to run but nothing is working for me, (I am also new at this)
binDepth binCount binDepth binCount
-0.11 170 -0.112 170
-0.11 178 -0.111 178
-0.11 161 -0.110 161
-0.10 167 -0.109 167
-0.10 191 ... ...
-0.10 156
-0.10 177
-0.10 174
-0.10 173
-0.10 179
-0.10 165
-0.10 178
-0.10 212
-0.09 191
-0.09 185
-0.09 191
  5 Comments
Walter Roberson
Walter Roberson on 31 May 2021
Don't use "format bank" ?
Or don't use round() with 2 decimal places?
Or change sprintf() or fprintf() or compose() to specify at %.3f format instead of a %.2f format ?
Andrew Forbes
Andrew Forbes on 1 Jun 2021
Edited: Andrew Forbes on 1 Jun 2021
The output from a 3rd party data set automatically truncated the data. The output is a 2 column text file. I am measuring differences to the millimeter so I I need to add in the 3rd decimal place. The output text file has 10 iterations of each measurement (e.g -1.09, -1.09, -1.09, -1.09, -1.09, -1.09, -1.09, -1.09, -1.09, -1.09) before moving to -1.08 etc… It is a loop i need to run to concatenate the additional digit (9, 8, 7, 6,5, 4, 3, 2, 1, 0…) When the number is negative it will be in descending order, (9, 8, 7, 6….) when it becomes a positive number it will be in ascending order (1, 2 ,3,…)

Sign in to comment.

Accepted Answer

Mathieu NOE
Mathieu NOE on 1 Jun 2021
hello
so my 2 cents suggestion, build on @DGM input (tx to him ! )
it just needed an additionnal correction term to be perfect (hopefully)
clearvars;
clc
%% data extraction
[out, delimiter, headerlines] = importdata('data.txt');
header = out.textdata;
data = out.data;
data1 = data(:,1);
data2 = data(:,2);
samples = length(data1);
myvector = (data1(1):0.001:data1(end)).'; % transpose for col vector
ind = find(diff(data1)>0); % find the index of the first "staircase" edge (this will be used later)
corr = data1(ind(1)) - myvector(ind(1)); % correction term
myvector = myvector + corr; % correction term added

More Answers (1)

DGM
DGM on 1 Jun 2021
Edited: DGM on 1 Jun 2021
Are you sure the data is being truncated, or is it rounded? Guessing the wrong answer means your alignment of additional digits will be off by 5.
If the column vector has known start and endpoints and a fixed stepsize, it would be easier and more certain to just rebuild it from scratch.
myvector = (startpoint:0.001:endpoint).'; % transpose for col vector

Categories

Find more on Large Files and Big Data in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!