Effacer les filtres
Effacer les filtres

Inquiry about ceil function.

3 vues (au cours des 30 derniers jours)
Angel Lozada
Angel Lozada le 19 Juin 2023
Modifié(e) : Stephen23 le 19 Juin 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

Réponse acceptée

Stephen23
Stephen23 le 19 Juin 2023
Modifié(e) : Stephen23 le 19 Juin 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

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by