help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FIXED (again): INTERP2 problem


From: Paul Kienzle
Subject: Re: FIXED (again): INTERP2 problem
Date: Sat, 26 Nov 2005 15:23:55 -0500

Consider a matrix, e.g.,

octave> X=toeplitz(1:5)
X =

  1  2  3  4  5
  2  1  2  3  4
  3  2  1  2  3
  4  3  2  1  2
  5  4  3  2  1

You want to be able to take slices of this matrix, such as the second row:

octave> X(2,:)
ans =

  2  1  2  3  4

or even the second and fourth row:

octave> X([2,4],:)
ans =

  2  1  2  3  4
  4  3  2  1  2

Maybe you don't want the whole slice, just the third and fifth columns:

octave> X([2,4],[3,5])
ans =

  2  4
  2  2

That's more or less what you are doing below, asking for forty randomly selected columns out of forty randomly selected rows. Obviously since your matrix is only 4x6 there are going to be some repeats, so Octave dutifully returns them.

- Paul


On Nov 26, 2005, at 1:43 PM, Pierre Baldensperger wrote:

Actually I'm pretty much a beginner with Octave / Matlab. At first, I didn't manage to keep the vectorized syntax because expressions like a(yidx,xidx) weren't interpreted the way I expected them to be. Actually I expected them to return the vector of elements a(yidx(i),xidx(i)) for i=1:size(xidx), but
something else shows up that I don't really understand. Example:

a = [ 1 2 3 4 5 6 ; 7 8 9 10 11 12 ; 13 14 15 16 17 18 ; 19 20 21 22 23 24 ]
xidx = floor(rand(40,1)*6)+1
yidx = floor(rand(40,1)*4)+1
result = a(yidx,xidx)
size(result)

ans =
 40  40

What's this beast? If somebody has a teacher's soul and could explain to me what this "something else" is, what this syntax actually does and what it can be used for: your clarifications are welcome (RTFM links if applicable :-)!



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]