Open In App

List Variables in Workspace With Sizes and Types in MATLAB

Last Updated : 22 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

MATLAB works with workspaces, which contain all variables, and their metadata. This makes accessing data in large codes easy. However, sometimes there are requirements for listing all the variables in the MATLAB terminal or properties of some particular variables.  Fortunately, MATLAB provides a method to get this job done; using the whos function.

whos Function

The whos function when called without any argument, lists all the variables in the current workspace with their properties. The syntax of the whos function is:

whos <optional parameters>

we shall see the optional parameters in later sections.

Example 1

Let us see the basic working of whos function.

Matlab




%vector 1
x = 1:10;
%vector 2
y = 3:6.7;
 
% listing all variables with their properties.
whos


Here, we have created two vectors, x, and y. Then, we call the whos function to see how it works.

Output:

 

As we can see, we got the name of the two variables, x, and y, and their size, space was taken in Bytes and data type. If there are some more attributes associated with any variables, they will be displayed in the last section. 

Using the Optional Parameters

In this section, we shall see the usage of optional parameters available with whos function. 

Listing variables that match a REGEX expression

The whos function can be used with REGEX expression. REGEX expressions are standard. the same can be used with the following syntax:

whos -regexp <expression>

Let us see an example of the same.

Matlab




%vector 1
vec_1 = 1:10;
%vector 2
vec_2 = 3:6.7;
%vector 3
x = 3:90;
 
% listing all variables that
% start with vec
whos -regexp vec*


Here, we have 3 variables and we list all the expressions that start with vec. The output will be:

 

Listing Particular Variables 

Now, we can list specific variables using the whos function and pass the variable names as parameters.

whos var1 var2 … varN 

In the following example, we use the same method to list some variables explicitly.

Matlab




%vector 1
vec_1 = 1:10;
%vector 2
vec_2 = 3:6.7;
%vector 3
x = 3:90;
 
whos vec_1 x


This will list the variables vec_1 and x, with their size and other metadata.

Output:

 



Similar Reads

How To Import Data from .CSV File With Numeric Values and Texts Into MATLAB Workspace?
A .csv file is a comma-separated file, in which consecutive data columns are separated by commas and the end of a line is the default EOL character. While dealing with small data, it is common to use a .csv file for storing it. In this article, we shall discuss how to import .csv files, with numeric data and their text headers as the column variabl
2 min read
Comparing Two Cell Arrays of Strings of Different Sizes in MATLAB
MATLAB is a high-performance language that is used for matrix manipulation, performing technical computations, graph plottings, etc. It stands for Matrix Laboratory. Cell Array: A cell Array in MATLAB is a data type that can store any type of data. Data is stored in cells in a cell array. It is initialized using { } i.e. curly braces. E.g. A = { 5,
2 min read
Global Variables in MATLAB
Variables in programming are generally storage spaces to store a certain type of data. There are many types of variables, but two commonly used types are local and Global variables. Generally, each MATLAB function has its own local variables. But sometimes for the sake of programming, we need to change the value of the local variable in another fun
4 min read
MATLAB - Variables
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
3 min read
How To Plot a Function of Two Variables in MATLAB?
In order to plot a function of two variables in Matlab first you have to know some functions like plot, meshgrid() function, and very well know about how to plot one variable functions in Matlab. You have to follow some main contents or you can say procedure to plot a function. Below is the process to plot two variables function in Matlab: Algorith
2 min read
Types of 2-D discrete data plots in MATLAB
Any data or variable that is limited to having certain values is known as discrete data. Many examples of discrete data can be observed in real life such as: The output of a dice roll can take any whole number from 1 to 6.The marks obtained by any student in a test can range from 0 to 100.The number of children in a house. When dealing with such da
4 min read
What are different types of denoising filters in MATLAB?
Digital images are prone to various types of noise that make the quality of the images worst. Image noise is a random variation of brightness or color information in the captured image. Noise is basically the degradation in image signal caused by external sources such as cameras. Images containing multiplicative noise have the characteristic that t
9 min read
Numeric Types in MATLAB
Numeric class in MATLAB includes signed and unsigned integers, single-precision floating-point numbers, and double-precision floating-point numbers. Generally, MATLAB stores all numeric values as double-precision floating-point. But, we can choose to store any number, or, an array of numbers, as integers or, as single precision, for better memory u
3 min read
Set Variable Data Types in MATLAB
There are many cases when a user has to import data into MATLAB script from various files. These file types could be .txt, .xlsx, .csv, .dat, etc. types. Now, each file type has its own method of defining data types. However, for computation purposes, MATLAB requires the data to be of numeric type, rather than character. Thus, there is a requiremen
3 min read
Difference Between MATLAB and Scilab
Performing computation with the help of programming languages was always been a focus for all mathematicians and statistician. Whereas to perform it efficiently it also depends on the scope of the problem. We have a variety of tools and languages to analyze and compute data. So let us discuss the most commonly used languages. 1. MATLAB : MATLAB is
2 min read
Article Tags :