Unable to control floating point display?

2 ビュー (過去 30 日間)
Roger Breton
Roger Breton 2022 年 3 月 14 日
コメント済み: Roger Breton 2022 年 3 月 15 日
I have this result :
There should be three Lab numbers on the third line but only L and a are showing, with two decimals of precision each (50.91 -46.21 ,). I have not completely figured out how to control the num2str conversion, the best I had was this :
Line1 = ['(X,Y) = ', num2str(posX), ', ', num2str(posY)];
Line2 = ['RGB = ', num2str(RGB(1,1,1)), ', ', num2str(RGB(1,1,2)), ' , ', num2str(RGB(1,1,3))];
Line3 = ['Lab = ', num2str(Lab(1,1,1),2), ', ', num2str(Lab(1,1,2),2), ' , ', num2str(Lab(1,1,3),2)];
Line4 = ['Lch = ', num2str(Lab(1,1,1),2), ', ', num2str(chroma,2), ' , ', num2str(hueAngle,3), '°'];
I have not figured out yet the proper parameters to get a conversion from double to string with no decimal part?

採用された回答

Stephen23
Stephen23 2022 年 3 月 14 日
編集済み: Stephen23 2022 年 3 月 14 日
It would be better to use SPRINTF rather than NUM2STR. For example:
Line1 = sprintf('(X,Y) = %u, %u', posX, posY);
Line2 = sprintf('RGB = %.0f, %.0f, %.0f', RGB(1,1,1:3));
Line3 = sprintf('RGB = %.2f, %.2f, %.2f', Lab(1,1,1:3));
  1 件のコメント
Roger Breton
Roger Breton 2022 年 3 月 14 日
Thank you so much!!!!

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 3 月 14 日
round()
  2 件のコメント
Roger Breton
Roger Breton 2022 年 3 月 14 日
Thank you so much Mr. Roberson :-)
Roger Breton
Roger Breton 2022 年 3 月 15 日
I ended up using your solution ;-)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by