11
Matlab Programming Tips
Part 2– Input / Output Commands (Review)
by
Shameer Koya
input Command
 input - Prompt for user input.
 Input is the simple basic command to request the
user input.
 Displays a prompt text for the user to understand
what data to be entered and waits for the user to
input a value and press the Return key.
 i = input('Enter the current value:')
 str = input(‘text’,'s') returns the entered text as a MATLAB
string, without evaluating expressions.
2
sscanf Command
 Read data as string and convert to the other formats
based on the definition.
 X = sscanf(str, format, size)
 Reads data from the vector str, converts it according to the
format, and store the results in array X.
 Argument ‘size’ is optional.
3
disp Command
 disp - (display) command displays variable values
or text on screen
 Displays each time on new line.
 Doesn't print variable name
 disp(variable_name) or disp('text string')
4
fprintf Command
 fprintf - Means file print formatted
 'fprintf' is used to formats data and displays the
results on the screen and to write the data in to a text
file.
 Can write to screen or to a file
 Can mix numbers and text in output
 Have full control of output display
 Basic Syntax is
 fprintf('Text to display')
5
 >> fprintf( 'How are you' )
 How are you>>
 Problem – Command Window displays prompt (>>) at end of text,
not at start of next line!
 To make the prompt to appear on the start of a new line,
n at the end of the fprintf text
 >> fprintf( Electrical Engineeringn' )
 Electrical Engineering
 >>
 Use n in middle of text to make MATLAB display
remainder of text on next line
 >> fprintf(' Electrical nEngineering')
 Electrical
 Engineering
6
fprintf …
 To format the display data, the formatting operators
are used.
 A formatting operator starts with a percentage
sign, %, and ends with a conversion character.
 Common conversion specifiers:
 %f fixed point (decimal always between 1's and 0.1's place,
e.g., 3.14, 56.8
 %e scientific notation, e.g, 2.99e+008
 %d integers (no decimal point shown)
 %s string of characters
 >> fprintf( 'Joe is %d weighs %f kilos', age,
weight )
 >> fprintf( 'Joe weighs %f kilos', n1 )
7
fprintf to format the output
fprintf to format the output …
 Examples
 >> age = 35;
 >> weight = 75.25;
 >> fprintf( 'Joe is %d weighs %f kilosn', age, weight )
 Joe is 35 weighs 75.250000 kilos
 >> fprintf( 'Joe weighs %4.4f kilosn', weight )
 Joe weighs 75.2500 kilos
 >> fprintf( 'Joe weighs %4.2f kilosn', weight )
 Joe weighs 75.25 kilos
8
fprintf to format the output…
 To display a percent sign, use %% in the text
 To display a single quote, use ' ' in the text (two
sequential single quotes)
 To display a backslash, use  in the text (two
sequential backslashes)
9

More Related Content

PDF
Matrices, Arrays and Vectors in MATLAB
PPT
How to work on Matlab.......
PPTX
History Of JAVA
PPTX
Java program structure
PPTX
Functions in c
PPTX
RTF
PPTX
06 Recursion in C.pptx
Matrices, Arrays and Vectors in MATLAB
How to work on Matlab.......
History Of JAVA
Java program structure
Functions in c
06 Recursion in C.pptx

What's hot (20)

PPTX
Matlab m files and scripts
PPTX
Presentation on function
PPTX
Inheritance In Java
PPTX
Type conversion
PDF
FUNCTIONS IN C PROGRAMMING.pdf
PDF
Top C Language Interview Questions and Answer
PPTX
Control and conditional statements
PPT
Strings Functions in C Programming
PPTX
Inheritance in java
PPTX
If else statement in c++
PPT
PDF
Managing I/O in c++
PPTX
Operators and expressions in c language
PDF
Clocked Sequential circuit analysis and design
PPTX
Data Types In C
PPT
Decision making and looping
PDF
PPS Arrays Matrix operations
PDF
9. statements (conditional statements)
PDF
Conditional operators
 
PPTX
Basic Input and Output
Matlab m files and scripts
Presentation on function
Inheritance In Java
Type conversion
FUNCTIONS IN C PROGRAMMING.pdf
Top C Language Interview Questions and Answer
Control and conditional statements
Strings Functions in C Programming
Inheritance in java
If else statement in c++
Managing I/O in c++
Operators and expressions in c language
Clocked Sequential circuit analysis and design
Data Types In C
Decision making and looping
PPS Arrays Matrix operations
9. statements (conditional statements)
Conditional operators
 
Basic Input and Output
Ad

Viewers also liked (6)

PPTX
Conditional Control in MATLAB Scripts
PPTX
Anonymous and Inline Functions in MATLAB
PPTX
MATLAB Scripts - Examples
PPTX
User defined Functions in MATLAB Part 1
PPTX
User Defined Functions in MATLAB Part-4
PPT
Matlab Introduction
Conditional Control in MATLAB Scripts
Anonymous and Inline Functions in MATLAB
MATLAB Scripts - Examples
User defined Functions in MATLAB Part 1
User Defined Functions in MATLAB Part-4
Matlab Introduction
Ad

Similar to MATLAB programming tips 2 - Input and Output Commands (20)

PPTX
Matlab ch1 (5)
PPT
Introduction to matlab
PPTX
Chap2programing.pptxdxnDSnfkezjnfqjdsckjqds
PDF
Matlab tutorial 3
PPT
To be able to add user input to m-files To be able to control the output fro...
PPT
8. MATLAB can generate random numbers using the rand command. rand on its own...
PPTX
PDF
Matlab commands
PPT
matlabchapter1.ppt
PPTX
Introduction to matlab lecture 3 of 4
PPT
Introduction to Matlab - Basic Functions
PPT
Chapter 01.ppt
PPT
Chapter 01.ppt
PDF
Mit6 094 iap10_lec01
PPT
MatlabIntro (1).ppt
PDF
A complete introduction on matlab and matlab's projects
PPT
matlab tutorial with separate function description and handson learning
PPT
matlab_tutorial.ppt
PPT
matlab_tutorial.ppt
Matlab ch1 (5)
Introduction to matlab
Chap2programing.pptxdxnDSnfkezjnfqjdsckjqds
Matlab tutorial 3
To be able to add user input to m-files To be able to control the output fro...
8. MATLAB can generate random numbers using the rand command. rand on its own...
Matlab commands
matlabchapter1.ppt
Introduction to matlab lecture 3 of 4
Introduction to Matlab - Basic Functions
Chapter 01.ppt
Chapter 01.ppt
Mit6 094 iap10_lec01
MatlabIntro (1).ppt
A complete introduction on matlab and matlab's projects
matlab tutorial with separate function description and handson learning
matlab_tutorial.ppt
matlab_tutorial.ppt

More from Shameer Ahmed Koya (8)

PPTX
User Defined Functions in MATLAB part 2
PPTX
MATLAB Programming - Loop Control Part 2
PPTX
Matlab Script - Loop Control
PPTX
Introduction to Matlab Scripts
PPTX
Matlab Programming Tips Part 1
PPTX
Polynomials and Curve Fitting in MATLAB
PPTX
MATLAB - Aplication of Arrays and Matrices in Electrical Systems
PPTX
MATLAB - Arrays and Matrices
User Defined Functions in MATLAB part 2
MATLAB Programming - Loop Control Part 2
Matlab Script - Loop Control
Introduction to Matlab Scripts
Matlab Programming Tips Part 1
Polynomials and Curve Fitting in MATLAB
MATLAB - Aplication of Arrays and Matrices in Electrical Systems
MATLAB - Arrays and Matrices

Recently uploaded (20)

PPTX
pharmaceutics-1unit-1-221214121936-550b56aa.pptx
PPTX
ACFE CERTIFICATION TRAINING ON LAW.pptx
PDF
Myanmar Dental Journal, The Journal of the Myanmar Dental Association (2015).pdf
PDF
Nurlina - Urban Planner Portfolio (english ver)
PDF
Civil Department's presentation Your score increases as you pick a category
PPTX
Integrated Management of Neonatal and Childhood Illnesses (IMNCI) – Unit IV |...
PDF
Compact First Student's Book Cambridge Official
PDF
Horaris_Grups_25-26_Definitiu_15_07_25.pdf
PDF
M.Tech in Aerospace Engineering | BIT Mesra
PDF
LIFE & LIVING TRILOGY - PART (3) REALITY & MYSTERY.pdf
PDF
Hospital Case Study .architecture design
PDF
Lecture on Viruses: Structure, Classification, Replication, Effects on Cells,...
PDF
MICROENCAPSULATION_NDDS_BPHARMACY__SEM VII_PCI Syllabus.pdf
PPTX
PLASMA AND ITS CONSTITUENTS 123.pptx
PDF
Solved Past paper of Pediatric Health Nursing PHN BS Nursing 5th Semester
PDF
LIFE & LIVING TRILOGY - PART - (2) THE PURPOSE OF LIFE.pdf
PPTX
4. Diagnosis and treatment planning in RPD.pptx
PDF
Laparoscopic Colorectal Surgery at WLH Hospital
PDF
Mucosal Drug Delivery system_NDDS_BPHARMACY__SEM VII_PCI Syllabus.pdf
PDF
Journal of Dental Science - UDMY (2021).pdf
pharmaceutics-1unit-1-221214121936-550b56aa.pptx
ACFE CERTIFICATION TRAINING ON LAW.pptx
Myanmar Dental Journal, The Journal of the Myanmar Dental Association (2015).pdf
Nurlina - Urban Planner Portfolio (english ver)
Civil Department's presentation Your score increases as you pick a category
Integrated Management of Neonatal and Childhood Illnesses (IMNCI) – Unit IV |...
Compact First Student's Book Cambridge Official
Horaris_Grups_25-26_Definitiu_15_07_25.pdf
M.Tech in Aerospace Engineering | BIT Mesra
LIFE & LIVING TRILOGY - PART (3) REALITY & MYSTERY.pdf
Hospital Case Study .architecture design
Lecture on Viruses: Structure, Classification, Replication, Effects on Cells,...
MICROENCAPSULATION_NDDS_BPHARMACY__SEM VII_PCI Syllabus.pdf
PLASMA AND ITS CONSTITUENTS 123.pptx
Solved Past paper of Pediatric Health Nursing PHN BS Nursing 5th Semester
LIFE & LIVING TRILOGY - PART - (2) THE PURPOSE OF LIFE.pdf
4. Diagnosis and treatment planning in RPD.pptx
Laparoscopic Colorectal Surgery at WLH Hospital
Mucosal Drug Delivery system_NDDS_BPHARMACY__SEM VII_PCI Syllabus.pdf
Journal of Dental Science - UDMY (2021).pdf

MATLAB programming tips 2 - Input and Output Commands

  • 1. 11 Matlab Programming Tips Part 2– Input / Output Commands (Review) by Shameer Koya
  • 2. input Command  input - Prompt for user input.  Input is the simple basic command to request the user input.  Displays a prompt text for the user to understand what data to be entered and waits for the user to input a value and press the Return key.  i = input('Enter the current value:')  str = input(‘text’,'s') returns the entered text as a MATLAB string, without evaluating expressions. 2
  • 3. sscanf Command  Read data as string and convert to the other formats based on the definition.  X = sscanf(str, format, size)  Reads data from the vector str, converts it according to the format, and store the results in array X.  Argument ‘size’ is optional. 3
  • 4. disp Command  disp - (display) command displays variable values or text on screen  Displays each time on new line.  Doesn't print variable name  disp(variable_name) or disp('text string') 4
  • 5. fprintf Command  fprintf - Means file print formatted  'fprintf' is used to formats data and displays the results on the screen and to write the data in to a text file.  Can write to screen or to a file  Can mix numbers and text in output  Have full control of output display  Basic Syntax is  fprintf('Text to display') 5
  • 6.  >> fprintf( 'How are you' )  How are you>>  Problem – Command Window displays prompt (>>) at end of text, not at start of next line!  To make the prompt to appear on the start of a new line, n at the end of the fprintf text  >> fprintf( Electrical Engineeringn' )  Electrical Engineering  >>  Use n in middle of text to make MATLAB display remainder of text on next line  >> fprintf(' Electrical nEngineering')  Electrical  Engineering 6 fprintf …
  • 7.  To format the display data, the formatting operators are used.  A formatting operator starts with a percentage sign, %, and ends with a conversion character.  Common conversion specifiers:  %f fixed point (decimal always between 1's and 0.1's place, e.g., 3.14, 56.8  %e scientific notation, e.g, 2.99e+008  %d integers (no decimal point shown)  %s string of characters  >> fprintf( 'Joe is %d weighs %f kilos', age, weight )  >> fprintf( 'Joe weighs %f kilos', n1 ) 7 fprintf to format the output
  • 8. fprintf to format the output …  Examples  >> age = 35;  >> weight = 75.25;  >> fprintf( 'Joe is %d weighs %f kilosn', age, weight )  Joe is 35 weighs 75.250000 kilos  >> fprintf( 'Joe weighs %4.4f kilosn', weight )  Joe weighs 75.2500 kilos  >> fprintf( 'Joe weighs %4.2f kilosn', weight )  Joe weighs 75.25 kilos 8
  • 9. fprintf to format the output…  To display a percent sign, use %% in the text  To display a single quote, use ' ' in the text (two sequential single quotes)  To display a backslash, use in the text (two sequential backslashes) 9