Inquiry about ceil function.

1 次查看(过去 30 天)
Hello.
I will really be appreciated if someone could help me with the follow line code (part of it).
I understand what ceil function does, however I do not understand why is necessary to sum + 1E-12
I have been looking in Matlab community, but I did not find an answer to this inquiry.
Also, I will really appreciate the link to read about this specific topic.
Regards.
clear;
data = readmatrix('Data 2');
t = seconds(data(:,1));
ixv = ceil(data(:,1) + 1E-12);
secv = accumarray(ixv, (1:size(data,1)).', [], @(x){data(x,[2 3])});
A2 = reshape(cell2mat(secv).', 2,10,[]);
tv = unique(ixv);
figure

采纳的回答

Stephen23
Stephen23 2023-6-19
编辑:Stephen23 2023-6-19
"I understand what ceil function does, however I do not understand why is necessary to sum + 1E-12"
In lieu of useful code comments explaining that magic number, my guess is that it is an attempt to account for some range of binary floating point errors in the input values. Compare:
ceil(10*(0:0.1:1))
ans = 1×11
0 1 2 4 4 5 6 7 8 9 10
ceil(10*(0:0.1:1)+1e-12)
ans = 1×11
1 2 3 4 5 6 7 8 9 10 11

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by