Thursday, November 19, 2020

, ,

fprintf command And fprintf format in MATLAB

  •  The fprintf command in MATLAB Programming use to displays formatted text which is centered on the icon and this fprint function can display formatSpec with a contents of var.
  • formatSpec  in MATLAB can be a character vector with the single quotes, or a string scalar.

Formatting for the fprint function in MATLAB : -

  •  formatting is starts with the a percentage sign, % and it will end with the conversion character.
  • Remember conversion character is required in formatting Operator.
  • But you can use the  flags, field , identifier,width, and subtype,precision operators between % and conversion character.

 List for the Conversion Character

Conversion Character
Conversion Character in MATLAB

Example of fprint function in MATLAB

The command

fprintf('YES YES');

displays this text 'YES YES' on the icon.

The follow command

fprintf('YES YES = %d',16);

uses the decimal notation format (%d) to display the variable 16.


Using fprintf in MATLAB With Function



Let's see this example for define a function in MATLAB : -
function []= fun2let(n)
 if n > 90.00
 fprintf('>>letter grade to %d is:A+\n',n)
 elseif n<=89.49 && n>=80.00
 fprintf('>>letter grade to %d is:B+\n',n)
 % YOU COMPLETE YOUR FUNCTION WITH OTHER TESTS
 elseif n<59.5 
 %    grade='Fail'
    fprintf('>> letter grade to %d is:Fail\n',n)
 end
 end

0 comments:

Post a Comment