0
0
MATLABdata~5 mins

First MATLAB program

Choose your learning style9 modes available
Introduction

Writing your first MATLAB program helps you learn how to tell the computer what to do using simple commands.

When you want to display a message on the screen.
When you want to check if MATLAB is working on your computer.
When you want to learn how to write and run MATLAB code.
When you want to start solving math problems using MATLAB.
Syntax
MATLAB
disp('Hello, world!')

disp is a command that shows text or numbers on the screen.

Text must be inside single quotes ' '.

Examples
This shows a different message on the screen.
MATLAB
disp('Welcome to MATLAB!')
This shows a number instead of text.
MATLAB
disp(123)
You can store text in a variable and then display it.
MATLAB
message = 'Good morning';
disp(message)
Sample Program

This program shows the message "Hello, world!" on the screen. It is the simplest way to start programming in MATLAB.

MATLAB
disp('Hello, world!')
OutputSuccess
Important Notes

Always end your commands with a semicolon ; to avoid showing extra output, but for disp you can leave it out.

You can run your program by typing its name in the MATLAB Command Window or pressing the Run button.

Summary

Your first MATLAB program uses disp to show messages.

Text messages must be inside single quotes.

Running this program helps you check MATLAB is ready to use.