Inquiry about ceil function.

5 views (last 30 days)
Angel Lozada
Angel Lozada on 19 Jun 2023
Edited: Stephen23 on 19 Jun 2023
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

Accepted Answer

Stephen23
Stephen23 on 19 Jun 2023
Edited: Stephen23 on 19 Jun 2023
"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

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!