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

727 vues (au cours des 30 derniers jours)
Alexandria Wynn
Alexandria Wynn le 26 Mar 2019
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 commentaire
Stephen23
Stephen23 le 27 Mar 2019
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 %%

Connectez-vous pour commenter.

Réponse acceptée

Stephan
Stephan le 26 Mar 2019
Modifié(e) : Stephan le 26 Mar 2019
percentError = 0.03696863;
fprintf('Percent Error: %0.8f %%', percentError);

Plus de réponses (1)

Richard Zapor
Richard Zapor le 31 Août 2023
Usage of char or '%' is possible.
fprintf('Percent Error: %0.8f %s', percentError,char(37));
or
fprintf('Percent Error: %0.8f %s', percentError,'%');

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by