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

652 ビュー (過去 30 日間)
Alexandria Wynn
Alexandria Wynn 2019 年 3 月 26 日
回答済み: Richard Zapor 2023 年 8 月 31 日
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 日
percentError = 0.03696863;
fprintf('Percent Error: %0.8f %%', percentError);
  1 件のコメント
Alexandria Wynn
Alexandria Wynn 2019 年 3 月 26 日
Thank you!!

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

その他の回答 (1 件)

Richard Zapor
Richard Zapor 2023 年 8 月 31 日
Usage of char or '%' is possible.
fprintf('Percent Error: %0.8f %s', percentError,char(37));
or
fprintf('Percent Error: %0.8f %s', percentError,'%');

カテゴリ

Help Center および File ExchangePreprocessing Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by