Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • 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

  • Thread starter Thread starter -
  • Start date Start date
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
 
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

Back
Top