format short, format long, format short E, format long E, format rat

25 ビュー (過去 30 日間)
Opariuc Andrei
Opariuc Andrei 2020 年 10 月 28 日
編集済み: Rik 2020 年 10 月 28 日
How can i represent a number let's say 1231312.1232323 with the formats long/short/long e /short e /rat more elegant or in a single code line without having to write 10 colums i was thinking of the fprintf and format spec commands . P.S i'm very much a beginner in matlab :) .

採用された回答

Rik
Rik 2020 年 10 月 28 日
For a single value I would suggest the fprintf function:
v=1234567.1234567;
fprintf('%.7f\n',v)
1234567.1234567
  4 件のコメント
Opariuc Andrei
Opariuc Andrei 2020 年 10 月 28 日
thx :) quote " I'n not sure why you would want that, but sure "
why not ? for diversity and cause it's fun learning new stuff and providing different answears /methods to the same question than the expected ones .
Rik
Rik 2020 年 10 月 28 日
Maybe it is just that I prefer having full control by using fprintf or sprintf, and I don't see the benefit of spamming the command window with the same value in different formats.
But at least you have an example here of how you can convert one syntax for format to another, and how you can use any object array in a for loop, which will then be processed column by column.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by