COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Local Maxima of 2D array

• Email
• Follow

```Hi,

Another question from me I'm afraid. I'm trying to implement a routine
which needs to be able to calculate the local maxima of a small window
moved across an array. That is, I have a large array and I will need to
move a small 3x3 array across it, each time working out what the maximum
value of that array is and storing its index (or selecting it in some
other way).

I've investigated various methods for doing this, including the dilate
method, but I can't seem to get them to work properly.

Is there any good (as in fast, efficient and elegant) way of doing this,
or will I be reduced to using for loops and lots of IF statements?

Best regards,

Robin
University of Southampton
```
 0
Reply Robin 1/19/2010 5:48:11 PM

See related articles to this posting

```On Jan 19, 5:48=A0pm, Robin Wilson <r.t.wil...@rmplc.co.uk> wrote:
> Hi,
>
> Another question from me I'm afraid. I'm trying to implement a routine
> which needs to be able to calculate the local maxima of a small window
> moved across an array. That is, I have a large array and I will need to
> move a small 3x3 array across it, each time working out what the maximum
> value of that array is and storing its index (or selecting it in some
> other way).
>
> I've investigated various methods for doing this, including the dilate
> method, but I can't seem to get them to work properly.
>
> Is there any good (as in fast, efficient and elegant) way of doing this,
> or will I be reduced to using for loops and lots of IF statements?
>
> Best regards,
>
> Robin
> University of Southampton

Hi Robin,

I asked something similar a few weeks ago, but I was looking for a
local minima in a running window of 9.  I think you can use the same
the guys suggested to me then, just changing the sign of the function
to convolve (so you find a max).  It's in here:

David
```
 0
Reply DavidPS 1/20/2010 3:35:17 PM

```On Jan 20, 10:35=A0am, DavidPS <dps.he...@gmail.com> wrote:
> On Jan 19, 5:48=A0pm, Robin Wilson <r.t.wil...@rmplc.co.uk> wrote:
>
>
>
>
>
> > Hi,
>
> > Another question from me I'm afraid. I'm trying to implement a routine
> > which needs to be able to calculate the local maxima of a small window
> > moved across an array. That is, I have a large array and I will need to
> > move a small 3x3 array across it, each time working out what the maximu=
m
> > value of that array is and storing its index (or selecting it in some
> > other way).
>
> > I've investigated various methods for doing this, including the dilate
> > method, but I can't seem to get them to work properly.
>
> > Is there any good (as in fast, efficient and elegant) way of doing this=
,
> > or will I be reduced to using for loops and lots of IF statements?
>
> > Best regards,
>
> > Robin
> > University of Southampton
>
> Hi Robin,
>
> =A0 I asked something similar a few weeks ago, but I was looking for a
> local minima in a running window of 9. =A0I think you can use the same
> the guys suggested to me then, just changing the sign of the function
> to convolve (so you find a max). =A0It's in here:http://tr.im/L0ob[groups=
>
> David

I don't think it's the same problem... correct me if I'm wrong, but I
think that Robin wants the maximum value within the window, regardless
of whether it's surrounded by lower values.

The only IDL-way I've thought of so far uses absurd amounts of memory
if your image is large, so I'm not even going to suggest it. Still

-Jeremy.
```
 0
Reply Jeremy 1/21/2010 1:02:52 PM

```On 19 Jan., 18:48, Robin Wilson <r.t.wil...@rmplc.co.uk> wrote:
> Hi,
>
> Another question from me I'm afraid. I'm trying to implement a routine
> which needs to be able to calculate the local maxima of a small window
> moved across an array. That is, I have a large array and I will need to
> move a small 3x3 array across it, each time working out what the maximum
> value of that array is and storing its index (or selecting it in some
> other way).
>
> I've investigated various methods for doing this, including the dilate
> method, but I can't seem to get them to work properly.
>
> Is there any good (as in fast, efficient and elegant) way of doing this,
> or will I be reduced to using for loops and lots of IF statements?
>
> Best regards,
>
> Robin
> University of Southampton

Dear Robin,
did you tried to reform that array to 3D and to find the MAXima and
their indices together with the keyword DIMENSION=3? Don't forget that
REFORM 'forms' rowwise.

Cheers

CR
```
 0
Reply chris 1/21/2010 2:55:02 PM

```> Dear Robin,
> did you tried to reform that array to 3D and to find the MAXima and
> their indices together with the keyword DIMENSION=3? Don't forget that
> REFORM 'forms' rowwise.
>
> Cheers
>
> CR

Hi Chris,

Thank you very much for your suggestion. I have looked at the
documentation for the REFORM function, but I'm not sure how to reform
the array to a suitable 3D form so that MAX will work with the
dimension=3 keyword. Could you provide some more details?

Best regards,

Robin Wilson
University of Southampton
```
 0
Reply Robin 1/21/2010 5:39:23 PM

```On 21 Jan., 18:39, Robin Wilson <r.t.wil...@rmplc.co.uk> wrote:
> > Dear Robin,
> > did you tried to reform that array to 3D and to find the MAXima and
> > their indices together with the keyword DIMENSION=3? Don't forget that
> > REFORM 'forms' rowwise.
>
> > Cheers
>
> > CR
>
> Hi Chris,
>
> Thank you very much for your suggestion. I have looked at the
> documentation for the REFORM function, but I'm not sure how to reform
> the array to a suitable 3D form so that MAX will work with the
> dimension=3 keyword. Could you provide some more details?
>
> Best regards,
>
> Robin Wilson
> University of Southampton

Dear Robin,

basically the code without a loop could be:

function cr_get_windowed_extrema,b,sx_k,sy_k

sk		=	long(sx_k)*long(sy_k)
sz		=	size(b,/dimensions)
sm		=	long(sz[0])*long(sz[1])
ind= (reform((transpose(lindgen(sz[0],sz[1])))[*],sx_k,sm/sx_k))
[0:sy_k-1,*]
mins= min(b[(reform((transpose((transpose(rebin(ind,sx_k,sm/sy_k,sy_k)
+\$
rebin(lindgen(1,1,sy_k),sx_k,sm/sx_k,sy_k),[0,2,1])),
[1,0,2])),sk,sm/sx_k))],\$
minind,max=maxs,subscript_max=maxind,dimension=1)
ind2=(lindgen(sx_k,sm/sk))[*,0:*:sy_k]
return, {mins:mins[ind2],minind:minind[ind2],maxs:maxs
[ind2],maxind:maxind[ind2]}
end

As potential output I got:

IDL> b=randomn(seed,9,9)
IDL> c=cr_get_windowed_extrema(b,3,3)
IDL> print,b
-0.232820     -1.81190     -1.79086   -0.0838641     -1.42229
-0.569596 -0.000931759     0.197937     0.203128
-0.742161     -1.04460     0.286660      1.59126     -1.18528
1.11088     -1.17374     -1.51570     0.156324
0.265435     -1.02502    -0.232129     0.259060    -0.825678
-0.386492     0.275219    -0.886818    -0.210116
1.20696    0.0987463     -1.22906    -0.155326      1.27177
-1.25504     0.650159    -0.864291    -0.915809
0.207192    -0.544278     -1.79930    0.0309544    -0.609460
-0.348675    -0.199986     0.518268     -1.03154
1.35320      1.08140  -0.00415816    -0.822823    -0.570877
-1.01163     -1.01084      1.87093     -1.31978
-0.486999     0.565098     0.140825    0.0224620     0.851600
0.922738    -0.779988     0.251917     0.834798
-1.06734      1.14913    -0.539062    -0.584468    -0.426683
0.869110     0.384573      1.50669     0.350647
0.478418     0.458704      1.72066      1.48684    -0.250672
0.920115    -0.324874     -1.49407   -0.0624892
IDL> print,c.mins
-1.81190     -1.79930     -1.06734
-1.42229     -1.25504    -0.584468
-1.51570     -1.31978     -1.49407
IDL> print,c.maxs
0.286660      1.35320      1.72066
1.59126      1.27177      1.48684
0.275219      1.87093      1.50669
IDL> print,c.minind
1                    14                    21
82                    92                   102
166                   179                   187
IDL> print,c.maxind
5                    15                    26
84                    91                   105
168                   178                   184

Hope, it works for you :) Maybe there are some unnecessary
computations, so you might optimize the code...

Cheers

CR
```
 0
Reply chris 1/22/2010 9:56:33 AM

```On Jan 19, 6:48=A0pm, Robin Wilson <r.t.wil...@rmplc.co.uk> wrote:
> Hi,
>
> Another question from me I'm afraid. I'm trying to implement a routine
> which needs to be able to calculate the local maxima of a small window
> moved across an array. That is, I have a large array and I will need to
> move a small 3x3 array across it, each time working out what the maximum
> value of that array is and storing its index (or selecting it in some
> other way).
>
> I've investigated various methods for doing this, including the dilate
> method, but I can't seem to get them to work properly.
>
> Is there any good (as in fast, efficient and elegant) way of doing this,
> or will I be reduced to using for loops and lots of IF statements?

Some kind of FOR loop is unavoidable, I think.

Depending of the size of your array, this code will do (most of) the
job efficiently. Elegant? Well...

x =3D [-1,  0,  1, -1, 0, 1, -1, 0, 1]
y =3D [-1, -1, -1,  0, 0, 0,  1, 1, 1]

; Or in general for a sliding (Kx x Ky) window
;x =3D lindgen(Kx)-Kx/2
;y =3D lindgen(Ky)-Ky/2
;x =3D (x[*,lindgen(Ky)])[*]
;y =3D (transpose(y[*,lindgen(Kx)]))[*]

sliding_3x3_max =3D shift(array, x[0], y[0])
for ii=3D1, 8 do sliding_3x3_max >=3D shift(array, x[ii], y[ii])

Note that the border case isn't handled. This is left as an exercise
for the reader :) Also, if you really need the index for each maximum
instead of the value, you must do a bit more work inside the loop.

My experience is that this method works well for operations on sliding
windows up to about 15x15, but for larger windows, the cost of the
(quite fast) SHIFT function starts to dominate when compared to the
straightforward double loop approach.

--
Yngvar
```
 0
Reply Yngvar 1/25/2010 3:55:22 PM

```If you have data in int or uint you could use the dilate procedure with a
3x3 array as structuring element. Dilate calculates the max and erode the
min! Have care with keywords, /GREY will be nessecary

Regards
Karsten

Am 19.01.10 18:48 schrieb "Robin Wilson" unter <r.t.wilson@rmplc.co.uk> in
i6CdnU6cXJD-bcjWnZ2dnUVZ8vudnZ2d@bt.com:

> Hi,
>
> Another question from me I'm afraid. I'm trying to implement a routine
> which needs to be able to calculate the local maxima of a small window
> moved across an array. That is, I have a large array and I will need to
> move a small 3x3 array across it, each time working out what the maximum
> value of that array is and storing its index (or selecting it in some
> other way).
>
> I've investigated various methods for doing this, including the dilate
> method, but I can't seem to get them to work properly.
>
> Is there any good (as in fast, efficient and elegant) way of doing this,
> or will I be reduced to using for loops and lots of IF statements?
>
> Best regards,
>
> Robin
> University of Southampton

```
 0
Reply karo 1/27/2010 5:00:54 AM

7 Replies
1085 Views

Similar Articles

11/30/2013 9:24:12 AM
page loaded in 3371551 ms. (0)

Similar Artilces:

array
In array I have content like this a = ["c" , "d", "e" , "f" ] But I need like this 'c','d','e','f' I want this for my following purpose insert into tablename values a . a has to subtitude in below statement,. -- Posted via http://www.ruby-forum.com/. On Fri, Feb 20, 2009 at 10:03 PM, Vetrivel Vetrivel <vetrivel.bksys@gmail.com> wrote: > In array I have content like this > > a = ["c" , "d", "e" , "f" ] > But I need like this > > 'c','d','e','f' > > I want this for my following purpose > insert into tablename values a . While the ruby to do that is trivial, i feel its more important that i point out you should _never_ construct a SQL statement like this - it's a classic security hole. http://en.wikipedia.org/wiki/SQL_injection or just google sql injection. Whatever tool you're using to interface with your database, it will certainly have a safe way to pass parameters into a sql statement. Please look that up - it will make the world safer

Array
Dear friend, How to i am use multidimensional array in awk and how to i access the elements in the array.Then tell the limit for the multidimensional array. "balasam" <bkmbala@gmail.com> writes: > How to i am use multidimensional array in awk and how to i > access the elements in the array.Then tell the limit for the > multidimensional array. There are no multidimensional arrays in awk. Rather, they are faked with a one-dimensional array by using the syntax arr[val1, val2] That syntax causes the index to be (val1 SUBSEP val2), i.e. a single concatenated string using the current value of SUBSEP. I'm not sure what you mean by the "limit" of the array. Arrays in awk are associative. You can use integers as the index, but they have no special status. If you do not know the index values in the array, use the loop form for(i in arr) { .... } Cheers, - Joel In article <1141034669.880148.271070@e56g2000cwe.googlegroups.com>, "balasam" <bkmbala@gmail.com> wrote: > Dear friend, > How to i am use multidimensional array in awk and how to i > access the elements

array of array?
Hi, there, I wonder, if that is possible to have a array of arrays, for example A(1)=a1(1:N,1:M); A(2)=a2(1:N,1:M); A(3)=a3(1:N,1:M); � If no such thing, is there any simple method to do the same things as dimension A(i,j,k) in Fortran? Could any one please input anything? Thanks hnliuhy wrote: > > > Hi, there, > I wonder, if that is possible to have a array of arrays, for > example > A(1)=a1(1:N,1:M); > A(2)=a2(1:N,1:M); > A(3)=a3(1:N,1:M); > � > > If no such thing, is there any simple method to do the same things > as > dimension > A(i,j,k) in Fortran? > > Could any one please input anything? > > Thanks cells are your answer: A{1}=a1; A{2}=a2; etc. notice that cells use curly braces. hnliuhy wrote: > > > Hi, there, > I wonder, if that is possible to have a array of arrays, for > example > A(1)=a1(1:N,1:M); > A(2)=a2(1:N,1:M); > A(3)=a3(1:N,1:M); > � > > If no such thing, is there any simple method to do the same things > as > dimension > A(i,j,k) in Fortran? > > Could any one please input anything? > > Thanks Probably you want a 3D-array. If a1, a2 and a3 are N*M

Cell array to string array
Ok if i have a cell array and i want to turn it in to an array of string or anything apart form cell how do I do it? Please help.....cell2mat does not work "Mohit Thukral" wrote in message <ig4ei8\$16i\$1@fred.mathworks.com>... > Ok if i have a cell array and i want to turn it in to an array of string or anything apart form cell how do I do it? Please help.....cell2mat does not work anyone?? "Mohit Thukral" wrote in message <ig4hrc\$5m2\$1@fred.mathworks.com>... > "Mohit Thukral" wrote in message <ig4ei8\$16i\$1@fred.mathworks.com>... > > Ok if i have a cell array and i want to turn it in to an array of string or anything apart form cell how do I do it? Please help.....cell2mat does not work > > anyone?? try to give example "Ade " <aogunmefun@tessera.com> wrote in message <ig4ir5\$b39\$1@fred.mathworks.com>... > "Mohit Thukral" wrote in message <ig4hrc\$5m2\$1@fred.mathworks.com>... > > "Mohit Thukral" wrote in message <ig4ei8\$16i\$1@fred.mathworks.com>... > > > Ok if i have a cell array and i want to turn it in to an array of string

beginner array of array
I have a 20KB txt file of data that looks something like this: lines of tab-separated fields. 001 jan2009 house 002 jan2008 barn 003 jun2007 trees 004 mar2006 garden 005 apr2003 lake 006 jul2001 mountain I'd like to load the entire file in an array and be able to refer to specific fields in specific records, such as the 1st field of the 4th item. I tried this but it obviously doesn't work. Can anyone show me the trouble? It would be much appreciated. Guy #!/usr/bin/perl my \$pfil="photos.txt"; my @records; my \$data = \@records; my \$total; if (open(FIL, \$pfil)) { \$total=0; while (<FIL>) { \$records[\$total] = split(/\t/); \$total++; } close FIL; } print "\$data->[3][0] \n"; "Guy" <someone@somewhere.nb.ca> writes: > I have a 20KB txt file of data that looks something like this: lines of > tab-separated fields. > 001 jan2009 house > 002 jan2008 barn > 003 jun2007 trees > 004 mar2006 garden > 005 apr2003 lake > 006 jul2001 mountain > > I'd like to load the entire file in an array and be able to refer to > specific fields

Waveform array to double array
Hello all, I'm having some issues with the waveform data type...&nbsp; I have a 2D waveform array (more than one plot), which I'd like to get the Y values out for a few specific plots.&nbsp; The problem is, all the built in VIs seem to only use scalar waveform data, which for my purposes, would get very cumbersome to get the right Y values out.&nbsp; Is there some way to just convert the waveform array's Y values to a double array? I realize that by nature, in a scalar waveform, the Y value is an array, but even if there could be some conversion done where the 2D waveform array converts to a 3D double array that could work...for me anyways. Thanks for any help, Geoff Try this sample. 7.0 format &nbsp; &nbsp; 2D waveform to dbl array.vi: http://forums.ni.com/attachments/ni/170/129376/1/2D waveform to dbl array.vi Thanks for the reply...&nbsp; Tha't more or less what I've got at the moment.&nbsp; I just thought there might be an easier way, since my 2D array is 6xvarying number of samples, and I need to get averaged values for 3 of those 6, and it's getting a little messy, and I imagine the number of For loops can't

creating array of an array
hi experts.. i have a problem. I want to creat an array, array. on button click this element array, will get attach to main array plz help me Hi Thandal, Use the "Build array" function! This function will "Concatenates multiple arrays or appends elements to an n-dimensional array". it doesn't work man , i already tried it. if you have ex.then send me Right click the Concatenate Array, and toggle the Concatenate Inputs option. But be aware, each row and each colomn in a 2d array will have the same size. So if you have one row with 10 elements, and you add a second row with 20 element, the first row will fill up with 10 zero's. If you don't want this, you'll have to build an array of clusters with arrays in it. Regards, Wiebe. "Thandal" <x@no.email> wrote in message news:50650000000500000062780100-1079395200000@exchange.ni.com... > it doesn't work man , > i already tried it. > if you have ex.then send me Hi Thandal, I agree with Wiebe and BJK. I you really need array, array then create an array in which you can put a cluster in which you can put another array. This kind of arrays are not really easy

Char array to double array
I have a char array which contains zeros and ones and i want to convert it to double array so i can process the contents of each cell. Can anyone help me? Dimitrios Tsarouchis: <SNIP char-to-double... one of the solutions c=char([1 0 1 1 0]) d=double(c) us us wrote: > Dimitrios Tsarouchis: > <SNIP char-to-double... > > one of the solutions > > c=char([1 0 1 1 0]) > d=double(c) OP might have been talking about a binary character string like '10110'. If that's the case, here is one of many solutions: >> c = '1011000100101'; >> d = double(c-'0') d = 1 0 1 1 0 0 0 1 0 0 1 0 1 - Randy

Sorting through an array of an array
;=> operator by hand. Brian. But how to do apply this to having 3 elements in the value of an array? container.sort_by { |x,y,z| *lost here* puts x <br> puts y <br> puts z <br> } Brian Mitchell wrote: > On 10/13/06, Dominic Son <dominicson@gmail.com> wrote: >> What method should i use? > Actually, the better way to sort in this scenario is to use sort_by. > > container.sort_by {|x| x[1]} > > No need to mess with the <=> operator by hand. > > Brian. -- Posted via http://www.ruby-forum.com/. On 10/13/06, Dominic Son <dominicson@gmail.com> wrote: > But how to do apply this to having 3 elements in the value of an array? > > container.sort_by { |x,y,z| *lost here* > puts x <br> > puts y <br> > puts z <br> > } Having more entries in the array doesn't change the number of arguments to the block. a = [] a << [1,2,3] a << [4,5,6] a << [7,8,9] a.sort_by do |element| [element[0], element[1], element[2]] end If you return an Array from sort_by's block, it will sort on the entries

Array within an array #2
\$array_floor = [] for i in (0..7) for n in (0..8) \$array_floor [n,i] = [i*var1,0.0,n*var2] end end I am trying to create a array, which basically forms a grid, which is evenly spaced in a Cartesian plane. The spacing is var1 and var2, in the x and z directions. Plan is to copy columns on these 'points', which is done in Sketchup using Ruby API scripts. So there are going to 8 and 9 columns respectively, and there are points when n = i, where there will be common columns. This is not working out for me very well. It makes sense to me, somehow it doesn't seem to be working (it returns with no values).Any suggestions? And If I want floors to this array, i.e. making it 3D, how will it work? -- Posted via http://www.ruby-forum.com/. Mahadev Ittina wrote: > \$array_floor = [] > for i in (0..7) > for n in (0..8) > \$array_floor [n,i] = [i*var1,0.0,n*var2] > end > end Almost every line of this code is problematic. To fix: * Never use global variables. * Instead of your "for" constructs, use "times". * Use the proper syntax for multidimensional arrays (which is array[x][y], not array[x, y]). array[x, y] has

Array of Exceptions
Is is possble to create an array of exceptions.Something like this:public Object [] x = new Object [10];Exception [] x = new Exception [10];x [0] = IllegalMyException;......public void y () throws x[0]{ throw new x[0];}try { y(); }catch {x[0] e}The above doesn't work. But is it because I have the syntax wrong, orit is simply not possible? pascal@ameritech.net wrote:> Is is possble to create an array of exceptions.> Something like this:> > public Object [] x = new Object [10];> Exception [] x = new Exception [10];> > x [0] = IllegalMyException;x[0] = new... involve formal parameters (cf. JLS 1.3 �14.20 and �8.4.6). Actually, I believe we could declare a "throws" clause with asuperclass of these arrayed exceptions. For simplicity, we could justdeclare as "throws Exception".On Mar 10, 10:07 am, Joshua Cranmer <Pidgeo...@epenguin.zzn.com>wrote:> pas...@ameritech.net wrote:> > Is is possble to create an array of exceptions.> > Something like this:>> > public Object [] x =3D new Object [10];> > Exception [] x =3D new Exception [10];>> > x [0] =3D IllegalMyException;>> x[0] =3D new

Subtotal array
I have this array: [{"acct":"A1","dr":100,"cr":100},{"acct":"A2","dr":200,"cr":200}, {"acct":"A1","dr":300,"cr",300},{"acct":"A2","dr":400,"cr",400}] How would I get the subtotal of each acct so that total for A1 dr/cr is 400 and total for A2 dr/cr is 600. TIA... On May 23, 6:35 pm, moua...@yahoo.com wrote: > I have this array: > > [{"acct":"A1","dr":100,"cr":100},{"acct"...;cr":100},{"acct":"A2","dr":200,"cr":200}, {"acct":"A1","dr":300,"cr":350},{"acct":"A2","dr":400,"cr":400}] alert(getTotal(d,"A1")) On May 23, 6:00 pm, "scripts.contact" <scripts.cont...@gmail.com> wrote: > On May 23, 6:35 pm, moua...@yahoo.com wrote:> I have this array: > > > [{"acct":"A1","dr":100,"cr":100},{"acct":"A2","dr":200,"cr":200}, > >

Array help!!
;checkbox" name=aix64testd value=aix64testd> <font color="oliveDrab" size=1%>presto </font><input type="checkbox" name=aix64testa value=aix64testa> <font color="oliveDrab" size=1%>psyn </font><input type="checkbox" name=aix64testb value=aix64testb> <font color="oliveDrab" size=1%>psynim </font><input type="checkbox" name=aix64testc value=aix64testc> <script type="text/javascript"> function checkAll(Array1) { var myArr = new Array('aixtestd...;> Why are you sending the object to the function? It is not needed the way it is coded. > <script type="text/javascript"> > > function checkAll(Array1) You never reference Array1. If this is the full code, you can remove it. Don't forget that if you remove it from the call, you need to remove it from the function and vice versa. { > var myArr = new > Array('aixtestd','aix64testa','aix64testb','aix64testc'); > for(var i; i<myArr.length;i++) { > document.myForm.myArr['+i+']=true

wstring array?
}; // C2552 Question 1. How should i initialize an array of wstring? Question 2. And what is wrong with the statement below. wstring cfMethods[] = {{L"setLabel"},{L""}}; Respects, Saurabh Aggrawal [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] Saurabh Aggrawal wrote: > 24: wstring cfMethods[] = {{L"setLabel"},{L""}}; > 25: wstring cfProperties[]= {{L"isVisible"},{L""}}; > 26: wstring cfEvents[] = > {{L"onLoad"},{L"onQueryTerminate"},{L"onTerminate"},{L""}}; The oversimplified answer is: wstring has a constructor, so you can't use {}-style initializers. However, the array DOES use {}-style initializers, so you have to use the outer set of {}'s! Write this instead (but leave off the periods at the beginning of each line, I added these to deal with Google's indent problems) .. wstring cfMethods[] = { .. wstring(L"setLabel"), .. wstring(L"") .. }; .. wstring cfProperties[]= { .. wstring(L"isVisible"

Array casting
I was wondering, is there a way in C++ to cast a 1D array such that it would be interpreted as a 2D (or higher) array without declaring a typedef? Here is a test programme to show what I am referring to: #include <iostream> using namespace std; const int maxX = 5; const int maxY = 3; int main() { //int oneDimArray[maxX*maxY] = {}; int *oneDimArray = new int[maxX*maxY]; for (int y = 0; y < maxY; ++y) { for (int x = 0; x < maxX; ++x) { int offset = y+maxY*x; oneDimArray[offset] = (x << 8) | y; } } /////////////////////////////////////////////////////// // Do I need to make typedef or is there another way? /////////////////////////////////////////////////////// typedef int (*int_array)[maxY]; int_array array = reinterpret_cast<int_array>(oneDimArray); for (int y = 0; y < maxY; ++y) { for (int x = 0; x < maxX; ++x) { cout << "(" << x << ", " << y << ") = (" << (array[x][y] >> 8) << ", " << (array[x][y] & 0xff) << ")" << endl; } } } Thanks for your help. Adrian

Array of variables
Does anyone know how I can create an array of variables? I am looking for something like this: U = [u1 u2 u3 u4, .... un] I should clarify: I am looking to use a for loop for this, for example: for i=1:n U = u_i end .... or something like that "Shaun Hurley" wrote in message <j5agv6\$dku\$1@newscl01ah.mathworks.com>... > I should clarify: > > I am looking to use a for loop for this, for example: > > for i=1:n > U = u_i > end > > ... or something like that This may still need clarification. Why won't U(n) = yourFunction work for you? You would want to preallocate of course. Barry On 9/20/2011 10:59 AM, Shaun Hurley wrote: > Does anyone know how I can create an array of variables? I am looking > for something like this: > > U = [u1 u2 u3 u4, .... un] Why (as yet unbeknownst to you :) ) you _do_NOT_ want to do that, and suggested alternatives... <http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F> -- "Shaun Hurley" <jumpinghurley@yahoo.com> wrote in message news:j5agv6\$dku\$1@newscl01ah.mathworks.com... > I should clarify: > > I am

array in hash
How do I add element to array which is a hash element? So far I have: ==================== push (\$data{"ny"}{list}, { dat=>2}); push (\$data{"ny"}{list}, { dat=>5}); push (\$data{"dc"}{list}, { dat=>9}); ==================== which generatees the following: ==================== Type of arg 1 to push must be array (not hash element) at hash.pl line 1, near "})" Type of arg 1 to push must be array (not hash element) at hash.pl line 2, near "})" Type of arg 1 to push must be array (not hash element) at hash.pl line 3, near "})" ===================== I want to end up with something like: data => { location => "ny" list = [ {dat=>2}, {dat=>5} ] }, location => "dc" list = [ {dat=>9}, ] }, Me wrote: > > How do I add element to array which is a hash element? The important thing to remember here is that Perl lists and hashes are inherently one dimensional. The trick used to make seemingly multidimensional structures is to use references as the elements. See perldoc perldsc. > So

Help with an array
; ? btw, the index file that it searches is formatted as such: (a line from the index file) http://127.0.0.1/fruit.html|apple|apples|pear|pears|banana|bananas| function s_search(\$query) { \$query = trim(strtolower(c_strip_chars(\$query))); \$search_data = @file(\$GLOBALS[index_file]) or die("<h4 align=\"center\">\$GLOBALS[err_no_search_db]</h4>"); \$pages_found = " "; foreach (\$search_data as \$search_page) { \$page_arr = explode("|", \$search_page); \$found_count = 0; \$qry_array = split('[, ]+',trim(strtolower(\$query))); foreach (\$qry_array as \$qry) { if (in_array(\$qry, \$page_arr)) { ++\$found_count; \$pages_found .= \$page_arr[0] . " "; } } if (\$found_count == count(\$qry_array)) \$result_arr[] = \$page_arr[0]; } return \$result_arr; } thanks. noone: > hello all. > this is a function that i am using which compares values submitted via > form, to an index file, and if there > is a match, it returns the name of the file that matched. > > the function supports multiple "keywords" entered in the form, for example > "apple pie". however, it > fails

invert array
I'm having trouble inverting (flipping) an array. example: xxx yyy zzz becomes zzz yyy xxx Im trying to make it happen with a for loop with a delete from array and build array inside, but it's not working. Any suggestions anybody? Hi Arend If it is a 1D array, there is a built-in vi for this operation in the array palette. Its name is "Reverse 1D array". Doc-Doc Arend wrote: > I'm having trouble inverting (flipping) an array. > > example: > xxx > yyy > zzz > > becomes > > zzz > yyy > xxx > > Im trying to make it happen with a for loop with a delete from array > and build array inside, but it's not working. Besides of most probably not using a shift register and choosing the worst possible solution in terms of performance you have a function in the array palette called Reverse 1D Array which does exactly what you want. Rolf Kalbermatter Uzytkownik "Arend" <x@no.email> napisal w wiadomosci news:5065000000080000003EEF0000-1079395200000@exchange.ni.com... > I'm having trouble inverting (flipping) an array. > > example: > xxx > yyy > zzz > > becomes >

fprintf with array
I am writing a code to display 3 colums to display a temparture and then two conversions Celcius = 0:100; Kalvin= Celcius + 273.15; Fahrenheit = (9/5)*Celcius+32; Tempature= [Celcius', Kalvin', Fahrenheit']; fprintf ('%10s %9s %11s\n', 'Celcius', 'Kalvin', 'Fahrenheit') fprintf('%10d %9f %11f\n',Tempature) I can't figure out how to get the last fprintf statement to display 1 value from each array instead of Celcius then Kalvin ect. What is wrong? "Dustin Sondenaa" <NA@NA.com> wrote in message <i92fvh\$hh7\$1@fred.mathworks.com>... > I am writing a code to display 3 colums to display a temparture and then two conversions > > Celcius = 0:100; > Kalvin= Celcius + 273.15; > Fahrenheit = (9/5)*Celcius+32; > > Tempature= [Celcius', Kalvin', Fahrenheit']; > fprintf ('%10s %9s %11s\n', 'Celcius', 'Kalvin', 'Fahrenheit') > fprintf('%10d %9f %11f\n',Tempature) > > I can't figure out how to get the last fprintf statement to display 1 value from each array instead of Celcius then Kalvin ect. I have