EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials Matlab Tutorial 3D Matrix in MATLAB
 

3D Matrix in MATLAB

Priya Pedamkar
Article byPriya Pedamkar

Updated March 22, 2023

3D Matrix in MATLAB

 

 

3D Matrix in MATLAB

MATLAB is a language used for technical computing. As most of us will agree, an easy-to-use environment is a must for integrating computing, visualizing, and finally programming tasks. MATLAB does the same by providing an environment that is easy to use and the solutions that we get are displayed in terms of mathematical notations, which most of us are familiar with. In this topic, we are going to learn about 3D Matrix in MATLAB.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Uses of MATLAB Include

  • Computation
  • Development of Algorithms
  • Modeling
  • Simulation
  • Prototyping
  • Data analytics (Analysis and Visualization of data)
  • Engineering & Scientific graphics
  • Application development

In this article, we will understand multidimensional arrays in MATLAB and, more specifically, 3- dimensional Matrix in Matlab.

Multidimensional array

It is an array in MATLAB which has two or more dimensions. You might be already knowing that the dimensions of a 2D matrix are represented by rows and columns.

Multidimensional array

Each element has two subscripts one is the row index and the other is the column index.

e.g. (1,1) element here represents Row number is 1 and the column number is 1.

What is a 3-D Matrix?

3-D Matrix is a multidimensional array that is an extension of two-dimensional matrices. As you can guess, they will have 3 subscripts, one subscript along with row and column indexes as for the 2D matrix. The third subscript in a 3D Matrix is used to represent the sheets or pages of an element.

3-D Matrix

e.g. Here element (2,1,1) represents ‘Row’ number 2 ‘Column’ number one and ‘Page’ number 1.

Creation of 3D Matrix

Let’s now understand how can we create a 3D Matrix in MATLAB

For a 3-dimensional array, create a 2D matrix first and then extend it to a 3D matrix.

  • Create a 3 by 3 matrix as the first page in a 3-D array (you can clearly see that we are first creating a 2D matrix)

A = [11 2 7; 4 1 0; 7 1 5]

  • Add a second page now. This can be done by assigning one more 3 by 3 matrix with index value 2 in the third dimension

A(: , :, 2) =  [1 2 5 ; 4 4 6 ; 2 8 1]

A[3×3]

A =

A(:,:,1)= 11 2 7
4 1 0
7 1 5
A(:,:,2) = 1 2 5
4 4 6
2 8 1

We can also use a function called cat Function to create multidimensional arrays.

For Example: Create a 3D array with 3 pages using cat function

X = cat(3,A,[3 7 1; 0 1 8; 2 5 4])

  • Here A is the 3D array created above
  • Argument at first place (3) tells which direction the array needs to be concatenated
  • Here concatenation is being done along with the pages

X=

X(:,:,1) = 11 2 7
4 1 0
7 1 5
X(:,:,2) = 1 2 3
4 4 6
2 8 1
X(:,:,3) = 3 7 1
0 1 8
2 5 4

Now, if we need to further expand this array, we can simply give the elements of 4th array that we need to add:

So to extend our above example, we will simply give,

B(:,:,4) = [1 2 1; 3 9 1; 6 3 7] and output will be:

X=

X(:,:,1) = 11 2 7
4 1 0
7 1 5
X(:,:,2) = 1 2 3
4 4 6
2 8 1
X(:,:,3) = 3 7 1
0 1 8
2 5 4
X(:,:,4) = 1 2 1
3 9 1
6 3 7

How can we access the elements of the array?

To do this simply use subscripts as integers. So, 2,3,1 element of a 3D Matrix will be the element present at 2nd row, 3rd column of the 1st page

To demonstrate this, let’s use the 3D matrix A which we used above,

Now, access = A(2,3,1) will give us 0 as output

Functions to manipulate the elements of a Multidimensional Array

MATLAB provides us with a couple of functions to manipulate the elements of a multidimensional array.

  • Reshape
  • Permute

Let’s understand these ones by one:

1. Reshape

This is useful mainly during visualization of data

For Example: Create a 6*5 matrics using two 3*5 matrices

  • A = [1 3 7 0 5; 2 0 4 1 3; 1 0 5 3 2];
  • A(:,:,2) = [1 7 2 5 0; 4 2 1 6 5; 1 1 4 5 0]; 
  • B = reshape(A,[6 5])

This will create a 2D matrix with 6 rows and 5 columns:

B = 6×5

1     7     5     7     5

2     4     3     2     6

1     5     2     1     5

3     0     1     2     0

0     1     4     1     5

0     3     1     4     0

As you can notice, RESHAPE will work column-wise, so first all the elements of A take along the column, for the first page. The same thing is then done for 2nd page

2. Permute

We can use this function if we want to rearrange the dimensions of the matrics. i.e., changing rows with columns or vice versa.

Example of Permute

  • P(:,:,1) = [3 5 3; 1 5 2; 0 8 5];
  • P(:,:,2) = [0 1 3; 6 7 1; 4 2 1]

Let’s now use PERMUTE function on P:

  • M = permute(P,[2 1 3])

The output that we will get will have rows and columns interchanged as follows:

M1 =

M1(:,:,1) = 3 1 0
5 5 8
3 2 5
P1(:,:,2) = 0 6 4
1 7 2
3 1 1

Recommended Articles

This is a guide to 3D Matrix in MATLAB. Here we discuss the uses of MATLAB, what is 3 D Matrix? and how to create 3D arrays in MATLAB and also some manipulations on them. You may also look at the following article to learn more –

  1. Matrix in Matlab
  2. MATLAB Version
  3. Vectors in Matlab
  4. Data Types in MATLAB
  5. Hive Data Type
  6. PL/SQL Data Types | Features | Examples
  7. Complete Guide to Vectors in R
  8. Quick Glance of Arrays in Matlab with Examples

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW