Hey guys wondering is anybody can help me out here. I have this array that prints this out:
0.6366, 0.0000, -0.2122, -0.0000, 0.1273
Which is fine.
But when I print it to a table using
set(handles.Table1, 'Data', cnarray);
It give me this:
0.6366, 3.8982e-17, -0.2122, -3.8982e-17, 0.1273
How could i fix this? I want those really low numbers to be zero. They are zero in the array when i print it out but not when i put it in a table. Help

 채택된 답변

James Tursa
James Tursa 2016년 10월 26일
편집: James Tursa 2016년 10월 26일

0 개 추천

The numbers are very small but not exactly 0. They just print as 0 with the display format used. To get them to exactly 0 you could do something like this:
>> tolerance = 1e-10;
>> x = [0.6366, 3.8982e-17, -0.2122, -3.8982e-17, 0.1273]
x =
0.6366 0.0000 -0.2122 -0.0000 0.1273
>> x(abs(x)<tolerance) = 0
x =
0.6366 0 -0.2122 0 0.1273
Note that now the numbers print as 0 and not 0.0000, which indicates that the numbers are exactly 0.

추가 답변 (1개)

Steven Lord
Steven Lord 2016년 10월 26일

0 개 추천

Use logical indexing to force those small values to be exactly 0.
A = [-1 -0.5 -1e-10 0.5 0 2 1e-6]
A(abs(A) <= 0.1) = 0

댓글 수: 1

Jesse Abruzzo
Jesse Abruzzo 2016년 10월 26일
This is also a good answer I just went this the other guys because he answered first. Thanks!

댓글을 달려면 로그인하십시오.

카테고리

질문:

2016년 10월 26일

댓글:

2016년 10월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by