How to use the Optional Parameters In MATLAB
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:
List Variables in Workspace With Sizes and Types in MATLAB
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.
Contact Us