How can I print out a zero instead of an asterisk while row-reducing a matrix?

조회 수: 14 (최근 30일)
Aditi Sekar
Aditi Sekar 2021년 6월 12일
편집: Adam Danz 2021년 6월 15일
A = [
1 2 1 1 13
0 1 2/3 1 9
0 0 1 15/8 123/8
0 0 * 1 5 ]
I used format rat at the top to try to get all the decimals into fractions but then instead of printing 0 it put an asterisk. Does anyone know a way to still get everything into fractions and keep the 0 in the last row?

답변 (1개)

Adam Danz
Adam Danz 2021년 6월 12일
As explained by the MathWorks Support Team in this answer, an asterisk indicates that the fraction is too long to display. The first example below is the same value as the first element of the second example but it appears as an asterisk in the second example because the results are too long to display.
format rat
1/1125899906842624
ans =
1/1125899906842624
A = [1/1125899906842624, pi, exp(1)]
A =
* 355/113 1457/536
Solution: You can round the values to a number of decimal places that meet your precision needs. Below I round them to 6dp.
A = round(A, 6)
A =
0 355/113 1457/536

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by