Reputation: 152
Can someone please explain the following MATLAB expression:
Matrix_l(2,:,1:5)=FX1(:,1:5)
I understand that all rows columns 1 to 5 from FX1
are copied. What I dont follow is the left side expression.
Upvotes: 1
Views: 124
Reputation: 3898
As I don't know the dimensions of your actual matrix, I have taken the dimensions of my own convenience.
FX1
of dimensions 5x7
Matrix_l
of dimensions 5x5x6
To understand physically, A vertical slice (visualize a black board) is copied to 2nd Horizontal slice (visualize the floor) of a 3D matrix.
The first 5 columns of the 2D matrix (i.e the one at the right - FX1
in your case) is copied to 2nd row and 1st 5 units in the 3rd dimensions of your 3D matrix (i.e the one at the left - Matrix_l
in your case)
Also, matlab can handle even more higher dimensions. Physically imagining those would be impossible. Still it's worth to know how this works.
Also take a look at Indexing
and Colon(:)
operator for more.
Upvotes: 9
Reputation: 1130
Your LHS-Matrix is a kind of 3D-Object. Thus you are inserting all field from all rows and columns 1 to 5 from FX1 into "second layer" of Matrix_I all rows and columns 1 to 5.
You can think of that as a slice of 3D-cube resulting in a 2D plane into which your data from FX1 gets inserted.
Hope that helps.
Upvotes: 1