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
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 ?
采纳的回答
Mathieu NOE
2021-6-1
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 个评论
更多回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File 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!