change negative data to zero in one table in matlab

9 visualizaciones (últimos 30 días)
Mounira
Mounira el 27 de Nov. de 2023
Movida: Dyuman Joshi el 27 de Nov. de 2023
Hello,
so i have table with negative values and also with some values above zero but very small, for example: 0.00001 and i want these values to be zero in the table,
can i make some kind of a code or what?
thanks in advance

Respuesta aceptada

chicken vector
chicken vector el 27 de Nov. de 2023
Editada: chicken vector el 27 de Nov. de 2023
% Create fictitious set of data:
tableData = rand(1e1) - .5
tableData = 10×10
0.0662 -0.0633 0.2803 0.0054 -0.2956 -0.0566 0.3033 -0.4808 0.2949 -0.0607 0.0877 0.3334 -0.1441 -0.2860 0.3349 0.1437 -0.0236 -0.3013 0.1927 0.4607 -0.0150 -0.4983 0.2688 0.3722 -0.1348 -0.1306 -0.3456 0.2598 -0.2027 0.2677 -0.3230 -0.2413 -0.4798 -0.0514 0.0638 -0.3500 0.1517 0.2282 0.1698 0.0196 0.1446 -0.4096 -0.1555 -0.4030 -0.4232 -0.3136 -0.2735 0.3195 -0.0417 -0.3340 0.3680 0.1401 -0.0174 0.4503 -0.1601 0.3643 -0.1591 -0.3438 0.4963 0.1290 -0.2027 -0.3589 -0.1596 0.2894 0.0880 0.1945 0.0019 0.4393 0.4007 0.4892 0.0860 -0.0007 0.4789 -0.4084 0.2700 -0.3130 -0.0826 0.3044 -0.3948 -0.4283 -0.3233 -0.0831 -0.0646 -0.1759 -0.2096 0.4733 0.2994 0.2015 0.3737 -0.2061 0.0421 0.4272 0.2534 0.1170 0.3878 -0.1996 -0.3837 -0.1266 0.2738 0.3225
% Define tolerance under which data is set to zero:
tol = 1e-2;
% Udpate table:
tableData(tableData<=tol) = 0
tableData = 10×10
0.0662 0 0.2803 0 0 0 0.3033 0 0.2949 0 0.0877 0.3334 0 0 0.3349 0.1437 0 0 0.1927 0.4607 0 0 0.2688 0.3722 0 0 0 0.2598 0 0.2677 0 0 0 0 0.0638 0 0.1517 0.2282 0.1698 0.0196 0.1446 0 0 0 0 0 0 0.3195 0 0 0.3680 0.1401 0 0.4503 0 0.3643 0 0 0.4963 0.1290 0 0 0 0.2894 0.0880 0.1945 0 0.4393 0.4007 0.4892 0.0860 0 0.4789 0 0.2700 0 0 0.3044 0 0 0 0 0 0 0 0.4733 0.2994 0.2015 0.3737 0 0.0421 0.4272 0.2534 0.1170 0.3878 0 0 0 0.2738 0.3225

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by