From: james bejon on 26 Mar 2010 10:48 Suppose I've got a 6-D (e.g. 3 x 5 x 2 x 2 x 2 x 6) matrix--say data = repmat(1:10, 72, 1); data = reshape(data, [3, 5, 2, 2, 2, 6]); Could someone tell me why data(:, :, [2, 1, 1, 1]) returns a 3D (3 x 5 x 4) matrix while data(:, :, 2, 1, 1, 1) returns what I want, namely a 2D (3 x 5) matrix?
From: Joshua Arnott on 26 Mar 2010 12:34 "james bejon" <jamesbejon(a)yahoo.co.uk> wrote in message <hoihf4$8uk$1(a)fred.mathworks.com>... > Suppose I've got a 6-D (e.g. 3 x 5 x 2 x 2 x 2 x 6) matrix--say > > data = repmat(1:10, 72, 1); > data = reshape(data, [3, 5, 2, 2, 2, 6]); > > Could someone tell me why > > data(:, :, [2, 1, 1, 1]) > > returns a 3D (3 x 5 x 4) matrix while > > data(:, :, 2, 1, 1, 1) > > returns what I want, namely a 2D (3 x 5) matrix? Hi James, Your first statement, data(:, :, [2, 1, 1, 1]), is asking for: all the data from the 1st dimension, all the data from the 2nd dimension, the 2nd 1st 1st and 1st entries from the third dimension. In this case, the other three omitted dimension queries are assumed by Matlab to be 1, so your call is identical to, data(:, :, [2, 1, 1, 1],1,1,1). So you're asking for the 2nd value of the 3rd dimension once, and the 1st value of the 3rd dimension three times. A simple example of this would be: >> data = ['a' 'b' 'c' 'd']; >> data([2 1 1 1]) ans = baaa Your second statement, data(:, :, 2, 1, 1, 1), is asking for: all the data from the first two dimensions, the second value from the third dimensions, and the first value for dimensions four through 6. I hope this helps. Josh.
From: james bejon on 26 Mar 2010 12:55 It does help. Thanks very much. But how, then, can I use a vector to reference elements of a matrix the way I'm trying to do? That is, suppose I have v = [2, 1, 1, 1]; and I want to use v to reference data(:, :, 2, 1, 1, 1) Can this be done (generically)? I'm currently experimenting with doing it by reshaping data as a 2d matrix (with the pages tiled, if you know what I mean) and then selecting the appropriate one. But it feels like there should be an easier way.
From: Bruno Luong on 26 Mar 2010 12:58 "Joshua Arnott" <j.arnott(a)lancs.ac.uk.matlab> wrote in message <hoinmc$s6f$1(a)fred.mathworks.com>... > In this case, the other three omitted dimension queries are assumed by Matlab to be 1, so your call is identical to, data(:, :, [2, 1, 1, 1],1,1,1). I would add the third-dimension is expanded as 24=(2*2*6, product of all tralling dimensions) and not 2, thus expression like data(:, :, [23 24]) is perfectly valid. Bruno
From: Bruno Luong on 26 Mar 2010 13:05 Sorry, I miss-calculated, should be read: > > I would add the third-dimension is expanded as 48=(2*2*2*6, product of all tralling dimensions) and not 2, thus expression like data(:, :, [47 48]) is perfectly valid. > Bruno
|
Next
|
Last
Pages: 1 2 Prev: Autocorrelation of state noise and measurement noise Next: surface of a convex 3d data |