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

711 次查看(过去 30 天)
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 个)

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 CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by