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

693 visualizaciones (últimos 30 días)
Alexandria Wynn
Alexandria Wynn el 26 de Mzo. de 2019
Respondida: Richard Zapor el 31 de Ag. de 2023
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 comentario
Stephen23
Stephen23 el 27 de Mzo. de 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 %%

Iniciar sesión para comentar.

Respuesta aceptada

Stephan
Stephan el 26 de Mzo. de 2019
Editada: Stephan el 26 de Mzo. de 2019
percentError = 0.03696863;
fprintf('Percent Error: %0.8f %%', percentError);

Más respuestas (1)

Richard Zapor
Richard Zapor el 31 de Ag. de 2023
Usage of char or '%' is possible.
fprintf('Percent Error: %0.8f %s', percentError,char(37));
or
fprintf('Percent Error: %0.8f %s', percentError,'%');

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by