Matrix with vector as element or 3d matrix or 3d tensor needed
Matrix with vector as element or 3d matrix or 3d tensor needed
(OP)
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
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





RE: Matrix with vector as element or 3d matrix or 3d tensor needed
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
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
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