TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Matlab

Variables in MATLAB Command Window

Introduction

In this tutorial, we will learn how to declare and use the variables in MATLAB command window prompt. Variables are used to store information. We can use the assignment operator (=) to store information.

Variables Assignment

Let’s use some variables and assign values to the them in the Command Window prompt.

Calculation using the variables.

>> a = 7;
>> b = 9;
>> ans = a*b

ans =

63

 

Variables in MATLAB

 

Variables a and b are assigned values. ‘a’ and ‘b’ are initialized to 7 and 9 values respectively. The product of and b is stored in ‘ans’ variable.

a = 7;

The statement declared the variable and stores the value 7 in the variable. We can reassign the variables if you want so.

The variable names and the current values will appear in the Current Workspace window.

Variable names

There are some rules for naming the variables in MATLAB.

  • The first letter of the variable name should be a letter.
  • Valid characters are letters and numbers.
  • Special characters are not allowed except underscore( _ ) .
  • Spaces are not allowed in variable names.
  • Variable names are case sensitive.

 

If you use invalid variable names, MATLAB will throw an error message and a suggested correction. You can use this command if you want, or hit Esc button to delete the suggestion.

Did you mean:
Suggested command

 

>> invalid$ = 10;
invalid$ = 10;
↑
Error: Invalid text character. Check for unsupported symbol, 
invisible character, or pasting of non-ASCII
characters.

>> 10name = 'Hello';
10name = 'Hello';
↑
Error: Invalid expression. Check for missing multiplication operator, 
missing or unbalanced delimiters, or other syntax error. 
To construct matrices, use brackets instead of parentheses.

Did you mean:
>> name = 'Hello';

Variable Names Errors

Example

>> radius = 5;
>> area = pi*radius^2

area =

78.5398

 

Matlab Variables Demo

 

pi is the floating point number and the value of  \large \pi. It is the ratio of circle’s circumference to the diameter.

Related Posts

Matlab /

Taylor series expansion MATLAB Example

MATLAB For Loop Script

Matlab /

For Loop Example in MATLAB

plot command MATALB

Matlab /

MATLAB 2D Plot command

Pie Chart Demo Matlab

Matlab /

Pie Chart Example using MATLAB

New Function

Matlab /

Functions in MATLAB

‹ Introduction to Matlab› In-Built Graphical Demo Programs in MATLAB

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version