필터 지우기
필터 지우기

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

조회 수: 470 (최근 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개)

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에서 Preprocessing Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by