# Formatting output and help in MATLAB

In the previous articles, the discussion revolved around the use of command window and how variables are added to working window. In the present article, the focus will be on how to format output and further use MATLAB for documentation without errors.

By default, MATLAB displays a line space between different lines in the output.

Line Spacing in Output

This line space can be removed using “compact command” which is used preceded by format.

Use of Compact Command

Furthermore, to bring the line spacing back in the output then, “loose command” preceded by format as shown below.

Use of loose command

### Formatting floating point numbers

Floating point are the numbers wherein the number of digits before and after the decimal is not fixed that is the decimal is floating. By default, MATLAB uses the command “short” to present output which has a fixed decimal with four digits after decimal. Image shows how the value of pi is presented in short format with four digits after decimal.

Formatting floating point number using short

The format of the result presented in the output can be changed using “format command” succeeded by the type to be used (long in case of present example). Image shows the presentation of value of pi in long format.

Formatting floating point number using long

The above image presents the generation of a 2 by 2 random matrix (wherein, Function rand ( ) is used to generate a matrix of random numbers) in case of “longEng” format. Furthermore, the presentation can be changed to the default short format any time by using format command (Image 6).

Formatting floating point numbers using “longEng” and default format

Similarly, there are many other formats are present for formatting output. Some of which are longE, shortG, long, shortEng, longEng, bank, hex and rat.

## View output page by page

Many a times, the output is so big that it exceeds the visible area in the command window. In such a scenario, to view the output screen by screen, “more on” command is used. Type more on command in the command window followed by a code that will generate a bigger output. Image represents an example to illustrate the more command.  Herein, ‘for loop’ is used to generate the matrix a fifty time as multiple of 5.

Use of more command in MATLAB

Output generated with “more” command

Above output is generated, which has generated matrix for five times, forty five times is still left which will be presented in proceeding pages. On pressing enter or spacebar after more, next page of output appears as in the below.

Second page of output generated using more command

In order to stop display of output, you need to type “q” after “more”. This will result in new line to carry on with other commands.

Quick tip: On typing “q” and pressing enter, the “q” disappears and new line appears as shown in Image 10

Terminating the generation of output using ‘q’

## Clearing the command window

Command window can be cleared without clearing the workspace window by using any of the following methods. “Home” function can be used to clear the present view of the command window without clearing the scroll buffer. Function “clc” is used to clear the command window along with scroll buffer.

Command window can also be cleared along with scroll buffer by following the path as follows:

`Home Tab-> Code Section-> Clear Commands-> Command Window`

## Long statements on multiple lines

Another form of presentation is to reflect content in single view. In order to do so the statement can be presented on multiple lines using ellipsis as shown in the below image.

Use of ellipsis for concatenation

A long character vector can also be created using single codes at the start and at end of the line as shown in the below image.

Use of “single quotes” for concatenation

The next article will present the ways in which MATLAB provides help to find content and understanding functions via internal tutorials and information in the software.

### Soumya Srivastava

Research Analyst at Project Guru
Soumya has completed her MBA in HR from National Institute of Technology (NIT), Kurukshetra and is Bachelor in Information Technology. She loves numbers, their patterns and the infinity nature possessed by them. When it comes to computers, she has interest in memory allocation and virtual memory. In her spare time she likes to read sun signs and personality traits. She believes in hard work and considers smart work to be incomplete without hard work.

### Related articles

• Search and help in MATLAB MATLAB provides various ways in which a user can access help within the software for better understanding of the functions. Similarly, many search options are provided to search text, characters and functions in the software in order to fix errors and avoid bugs.
• Adding variables to workspace window in MATLAB As discussed in the previous article, workspace is a space wherein the variables used and created in a study are displayed. The variables can also be imported from data files or other programs.
• Matrices and arrays in MATLAB The basics of MATLAB were discussed in the previous module. It covered topics on interface of MATLAB software and the basic operations of MATLAB along the help and documentation features.
• Introduction of basic MATLAB interface and quick access tools Matrix Laboratoryn (MATLAB) is a high-level language that is matrix based and includes an interactive environment for numerical computation, visualization,development and programming which was originally written in FROTRAN (Formual Translation). The present module is based on R 2017a […]
• Handling text value and characters in MATLAB If the text value itself contains single quote; eg. Sam’s in the image 2 below, then three single quotes are used within the statement. Two for text and one for the apostrophe.

We are looking for candidates who have completed their master's degree or Ph.D. Click here to know more about our vacancies.