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

1 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2021-5-31
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 2021-6-1
编辑:Andrew Forbes 2021-6-1
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,…)

请先登录,再进行评论。

采纳的回答

Mathieu NOE
Mathieu NOE 2021-6-1
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

更多回答(1 个)

DGM
DGM 2021-6-1
编辑:DGM 2021-6-1
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

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by