How do I print a "%" when using fprintf?

I need to have the display window have a "%" after the rest of my printing.
My code looks likes this:
fprintf('Percent Error: %0.8f %', percentError);
It is currently printing "Percent Error: 0.03696863 ", but I need it to print "Percent Error: 0.03696863%"

1 件のコメント

Stephen23
Stephen23 2019 年 3 月 27 日
The fprintf documentation explains how to define special characters, in the table entitled Special Character it shows:
Special Character Representation
Single quotation mark ''
Percent character %%

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

 採用された回答

Stephan
Stephan 2019 年 3 月 26 日
編集済み: Stephan 2019 年 3 月 26 日

15 投票

percentError = 0.03696863;
fprintf('Percent Error: %0.8f %%', percentError);

その他の回答 (1 件)

Richard Zapor
Richard Zapor 2023 年 8 月 31 日

0 投票

Usage of char or '%' is possible.
fprintf('Percent Error: %0.8f %s', percentError,char(37));
or
fprintf('Percent Error: %0.8f %s', percentError,'%');

カテゴリ

ヘルプ センター および File ExchangeElementary Math についてさらに検索

質問済み:

2019 年 3 月 26 日

回答済み:

2023 年 8 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by