Filter löschen
Filter löschen

Inquiry about ceil function.

2 Ansichten (letzte 30 Tage)
Angel Lozada
Angel Lozada am 19 Jun. 2023
Bearbeitet: Stephen23 am 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

Akzeptierte Antwort

Stephen23
Stephen23 am 19 Jun. 2023
Bearbeitet: Stephen23 am 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

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by