Borrar filtros
Borrar filtros

Inquiry about ceil function.

3 visualizaciones (últimos 30 días)
Angel Lozada
Angel Lozada el 19 de Jun. de 2023
Editada: Stephen23 el 19 de Jun. de 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

Respuesta aceptada

Stephen23
Stephen23 el 19 de Jun. de 2023
Editada: Stephen23 el 19 de Jun. de 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

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by