MATLAB - Variables Last Updated : 23 May, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Prerequisite: Getting Started with MATLAB A variable in simple terms is a storage place that has some memory allocated to it. Basically, a variable used to store some form of data. Different types of variables require different amounts of memory and have some specific set of operations that can be applied to them. The Matlab workspace store all the variables that you create or use during a session. Creating VariablesTo create a variable enter the name of the variable in the command window, followed by an = operator, and then assign it some values. Example: MATLAB % MATLAB code for variable initialization % % First variable % a=10; % Second variable % b=10; % Third variable % num=10; % Fourth variable % sum=100; Output: Note: If you don't put ';' after the variable name, Matlab will display its content after hitting enter.If you don't give any name to your variable by default Matlab name it with an answer.By default, Matlab treats all variables as matrices if you write just 1 it will store it as 1x1 matrix. To display the content of the Matlab variable you just need to type the name of the variable, and it will show its content on Command-Line: Example: Matlab % MATLAB Code for display variable % % value in command window % % First variable 5 a a = 100 % Second variable % b b = 200 Output: Multiple Assignments of Variables We can also define the multiple variables in a single line using ";" operator. Example: Matlab % MATLAB code for multiple variable % % assignment in single line % x = 12; y = 2; z = x*y; disp('Result z ='); disp(z); Output: Who command Who lists in alphabetical order the names of all variables in the currently active workspace. To use this command variables should be present in the active workspace and memory allocated to each variable is necessary. Example: Matlab % MATLAB code for Who command % x = 12; y = 2; z = x*y; disp('Result z ='); disp(z); who output: Assigning Vectors to variables A vector is a one-dimensional array of numbers. Matlab allows you two types of vector: Row VectorColumn Vector. Row Vectors are created by enclosing numbers in square brackets separating with either space or comma. Example: MATLAB % MATLAB program for row vector % rowVector = [1 2 3 4 5] Output: Column Vectors are created by enclosing numbers in square brackets, separating each number with ;(semicolon). Example: MATLAB % MATLAB program for column vector % columnVector = [1; 2; 3; 4; 5] Output: Assigning Matrices to variablesA Matrix is a two-dimensional array of numbers. In Matlab, matrices are created by enclosing numbers in a square bracket write each row of numbers with space or comma separate and after each row put a semicolon. The below code will create a 3x3 matrix: Example: MATLAB % MATLAB program for 3x3 Matrix % matalbMatrix = [ 1 2 3; 4 5 6; 7 8 9] Output: Comment More infoAdvertise with us Next Article MATLAB - Variables Y yahiyamansuri14 Follow Improve Article Tags : Java Mathematical MATLAB DSA Practice Tags : JavaMathematical Similar Reads DSA Tutorial - Learn Data Structures and Algorithms DSA (Data Structures and Algorithms) is the study of organizing data efficiently using data structures like arrays, stacks, and trees, paired with step-by-step procedures (or algorithms) to solve problems effectively. Data structures manage how data is stored and accessed, while algorithms focus on 7 min read Java Tutorial Java is a high-level, object-oriented programming language used to build web apps, mobile applications, and enterprise software systems. It is known for its Write Once, Run Anywhere capability, which means code written in Java can run on any device that supports the Java Virtual Machine (JVM).Java s 10 min read Java OOP(Object Oriented Programming) Concepts Java Object-Oriented Programming (OOPs) is a fundamental concept in Java that every developer must understand. It allows developers to structure code using classes and objects, making it more modular, reusable, and scalable.The core idea of OOPs is to bind data and the functions that operate on it, 13 min read Java Interview Questions and Answers Java is one of the most popular programming languages in the world, known for its versatility, portability, and wide range of applications. Java is the most used language in top companies such as Uber, Airbnb, Google, Netflix, Instagram, Spotify, Amazon, and many more because of its features and per 15+ min read Quick Sort QuickSort is a sorting algorithm based on the Divide and Conquer that picks an element as a pivot and partitions the given array around the picked pivot by placing the pivot in its correct position in the sorted array. It works on the principle of divide and conquer, breaking down the problem into s 12 min read Merge Sort - Data Structure and Algorithms Tutorials Merge sort is a popular sorting algorithm known for its efficiency and stability. It follows the divide-and-conquer approach. It works by recursively dividing the input array into two halves, recursively sorting the two halves and finally merging them back together to obtain the sorted array. Merge 14 min read Data Structures Tutorial Data structures are the fundamental building blocks of computer programming. They define how data is organized, stored, and manipulated within a program. Understanding data structures is very important for developing efficient and effective algorithms. What is Data Structure?A data structure is a st 2 min read Arrays in Java Arrays in Java are one of the most fundamental data structures that allow us to store multiple values of the same type in a single variable. They are useful for storing and managing collections of data. Arrays in Java are objects, which makes them work differently from arrays in C/C++ in terms of me 15+ min read Bubble Sort Algorithm Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in the wrong order. This algorithm is not suitable for large data sets as its average and worst-case time complexity are quite high.We sort the array using multiple passes. After the fir 8 min read Breadth First Search or BFS for a Graph Given a undirected graph represented by an adjacency list adj, where each adj[i] represents the list of vertices connected to vertex i. Perform a Breadth First Search (BFS) traversal starting from vertex 0, visiting vertices from left to right according to the adjacency list, and return a list conta 15+ min read Like