Why are all the negative values in the matrix show as 0?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
JCH
el 8 de Feb. de 2023
Comentada: Steven Lord
el 8 de Feb. de 2023
The code below creates a matrix to do calculations, however, the negative values results are show in the matrix as 0. Why would this happen and how to keep those negative values instead of 0. Thank you.
load Foveal
T = ans;
T_1002 = T(matches(T.message,'1002'),:);
T_ENDSACC = T(matches(T.message,'ENDSACC'),:);
[x1 ~] = size(T_ENDSACC);
[x2 ~] = size(T_1002);
T_diff = zeros(x1,x2);
for q = 1:x1
T_diff(q,:) = T_ENDSACC.reltime(q) - T_1002.reltime(:);
end
0 comentarios
Respuesta aceptada
Voss
el 8 de Feb. de 2023
reltime is of class uint32, as shown here:
load Foveal
T = ans;
class(T.reltime)
An unsigned integer cannot be negative. If you want to allow negative values use a different type such as a signed integer or a floating-point (such as single or double). Here I'll make reltime into a double:
T.reltime = double(T.reltime);
And then run the rest of the code:
T_1002 = T(matches(T.message,'1002'),:);
T_ENDSACC = T(matches(T.message,'ENDSACC'),:);
[x1 ~] = size(T_ENDSACC);
[x2 ~] = size(T_1002);
T_diff = zeros(x1,x2);
for q = 1:x1
T_diff(q,:) = T_ENDSACC.reltime(q) - T_1002.reltime(:);
end
T_diff
3 comentarios
Steven Lord
el 8 de Feb. de 2023
FYI for the integer types you can use intmin and intmax to determine the range of allowed values for that type.
intmin('uint32')
intmax('uint32')
Assignment of values outside that range truncates.
x = ones(1, 2, 'uint32')
x(1) = -1 % -1 is < intmin('uint32') so MATLAB stores intmin('uint32')
x(2) = 1e11 % 1e11 is > intmax('uint32') so MATLAB stores intmax('uint32')
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!