concatenate repeating digit to the end of a column in numeric matrix
1 view (last 30 days)
Show older comments
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
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 ?
Accepted Answer
Mathieu NOE
on 1 Jun 2021
hello
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
0 Comments
More Answers (1)
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
0 Comments
See Also
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!