How do I remove trailing zeros after rounding a matrix while retaining current rows/columns format?
이전 댓글 표시
I am trying to display a matrix that with numbers all rounded off to 1 decimal point. Currently when I round, there is a 0 that remains in the hundreths place of each number. I'd like to remove this last zero so that all my numbers only display out to the tenths place.
I have tried using the fprintf function as well as the sprintf function but I always lose the rows/column format of my matrix. Is there a way to round and then shorten an entire matrix of numbers so that there aren't any trailing zeros?
matrix = [1.34, 3.45, 2.34; 0.54, 21.34, 0.34; 11.81, 9.94, 10.02]; %3x3 matrix of data
round_matrix = round(matrix, 1); %3x3 matrix of data rounded to 1 decimal place
%My attempts thus far at removing the trailing zeros
disp_matrix = sprintf('%.1f', rounded_matrix); %This resulted in a string of all of my numbers mashed together
disp_matrix = fprintf('%.1f\n',round(Table_outnumeric)); %This resulted in all of my numbers being converted into a single column
채택된 답변
추가 답변 (1개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!