|
"Nikolas tuc" <nmihailidis@gmail.com> wrote in message <hkgc5l$9uo$1@fred.mathworks.com>...
> Hi there,
>
> I have a 3d matrix R(5,5,3) and I am doing the following operations:
> for i = 1:5
> for j =1:5
> rt = R(i, j, :);
> rt = rt(:);
> end
> end
>
> What does the rt = rt(:) mean? What is the new form that the rt matrix gets?
> I would really appreciate if you could send me a numerical example.
>
> Thank you in advance.
> NM
Using the variable editor, it seems that rt=R(i,j,:) keeps rt in 3-dimensions.
I created R(5,5,3). R(5,5,1)=11, R(5,5,2)=12, R(5,5,3)=13.
Then, rt = R(i, j, :); created rt as a 1x1x3 with the following:
val(:,:,1) = 11
val(:,:,2) = 12
val(:,:,3) = 13
Finally, rt=rt(:) turns rt into a regular ol' vector with values [11;12;13].
So it seems that the first line, rt = R(i, j, :), is retaining all the dimensions, even when they are only one. Whereas rt(:) is enumerating all the values and storing them in rt. So this last line just gets rid of any 1-long dimensions is my guess.
I'm new to this wonderful Matlab array referencing, too. It's fun, eh? You may get a few tips if you can find some of my recent posts where I asked similar questions.
|