Accessing Table Elements
By Smooth Parenthesis ():
This method returns requested columns and table variables.
Syntax:
Table (<number of rows>, <variable list>)
Let us index the first two rows and the first and third variables of the above table.
Example 3:
Matlab
% MATLAB Code name = { 'Harry' ; 'Mark' ; 'Steven' }; age = [23; 54; 13]; Employed = logical([1;0;1]); emp = table(name,age,Employed); % Accessing the said rows and columns emp(1:2,[1,3]) |
Output :
This extracted first 2 rows from first and third variable.
By Dot Notation:
The dot notation returns the passed variable as an array.
Example 4:
Matlab
% MATLAB Code for dot notation name = { 'Harry' ; 'Mark' ; 'Steven' }; age = [23; 54; 13]; Employed = logical([1;0;1]); emp = table(name,age,Employed); % Accessing age of second and third row emp.age(2:3) |
Output:
By Curly Braces Notation {}:
This method returns a concatenated array in the range of given rows and table variables.
Example 5:
Matlab
% MATLAB Code for curly braces notation name = { 'Harry' ; 'Mark' ; 'Steven' }; age = [23; 54; 13]; Employed = logical([1;0;1]); emp = table(name,age,Employed); % Accessing a sub table as an array emp{2:3,[2,3]} |
Output:
Tables in MATLAB
Table is an array data type in MATLAB that stores column-based or tabular data of same or different types. A table stores each column-oriented data under a variable name (column name). These table columns can have different data types in each however, the number of data points in every column must be the same.