Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matrix with vector as element or 3d matrix or 3d tensor needed

Status
Not open for further replies.

Guest
Hi,

i am a new matlab user. I need to generate a above mentioned (subject) datatype. Is it possible. Thanks for your help in advance.

jfrenzel
 
Replies continue below

Recommended for you

Yes, you can define a 3D matrix. For example, a 3x3x3 matrix of 1's
Code:
A(:,:,1) = [1, 1, 1; 1, 1, 1; 1, 1, 1];
A(:,:,2) = [1, 1, 1; 1, 1, 1; 1, 1, 1];
A(:,:,3) = [1, 1, 1; 1, 1, 1; 1, 1, 1];
% A is a 3x3x3 3d matrix
The indices are in the form (row,column,page)

So to extract the second page of this 3d matrix, A, you would use
Code:
B = A(:,:,2); % B is a 3x3x1 3d matrix
However, this will still leave you with a 3D matrix (3x3x1) but the 3rd dimension will have a value of 1. Some matlab functions don;t like this. Using the "squeeze" function removes these "singleton" dimensions
Code:
C = squeeze(A(:,:,2); % C is a 3x3 2d matrix
I don't think you can perform tensor calculations directly though although there may be some toolboxes available.

Full versions of matlab support n-dimensional spaces. "Student" versions are restricted to 3d I think.

Older versions of Matlab do not support anything above 2D matrices.

M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor