Re: Array subscripting with multiple dimensions

From: David B. Reusch <dreusch_at_nyahnyahspammersnyahnyah>
Date: Tue Mar 11 2014 - 08:12:23 MDT

Hi Emma,

The "3" in "v2 = v(1:7:3)" is the stride value for the range subscript.
In this case it means select every third element in the range one to
seven, i.e., 1, 4, 7.

You get an error from "x=v(:,55:56:61:62,:)" because this is the wrong
syntax for the range subscript, the ":62" is extraneous. Plus what you
are actually saying is give me a range from 55 to 56 with a stride of
61. This will have just one element, 55.

I *think* what you want is something like this:
If you're using the index list more than once, first create a vector
with the desired non-sequential indices
ix=(/55,56,61,62/)
x=v(:,ix,:)

Or, if it's a one=time thing and you don't want the extra variable, just do:
x=v(:, (/55,56,61,62/), :)

Hope this helps,
Dave

Emma Catherine TURNER said the following on 3/11/2014 7:12 AM:
> Hi,
>
> I am trying to sub-select dimensions of a multi dimension array, and for
> one of the dimensions the range is non consecutive.
>
> For example the array v is 1000x100x8000 in size.
>
> I want all of the first dimension, all of the last dimension, and
> element 56, 57, 62 and 63 of the second dimension. So what I am doing is:
>
> x=v(:,55:56:61:62,:)
>
> but this is throwing up errors. However if it were a one dimensional
> array such as in the examples in the NCL help pages..
> v = (/0,1,2,3,4,5,6,7,8,9/)
> v2 = v(1:7:3) > v2 is an array containing the
> elements 1,4,7
> Apparently this works though?
>
> Can you help please?
>
> Thanks
> Emma T
>
>

-- 
Associate Research Professor of Climatology
Dept of Earth and Environmental Science
MSEC 304; 801 Leroy Pl
New Mexico Tech
Socorro, NM 87801
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Mar 11 08:12:37 2014

This archive was generated by hypermail 2.1.8 : Fri Mar 14 2014 - 15:08:52 MDT