Re: Max value vector [message #15528 is a reply to message #15496] |
Sun, 23 May 1999 00:00   |
Evan Fishbein
Messages: 4 Registered: May 1999
|
Junior Member |
|
|
Tom,
I have a routine that finds the max and min over the first index of a
multidimension array
using a for loop as you described. You need to make sure that the for loop
variable is a long by initializing it to long
The code below takes x1(n1,n2...nn) and returns lu(n2..nn,2) where lu(...,0)
are the lowerbounds and (lu(...1) are the upperbounds
function lubound, x1, ignore=ignore, all=all
;
; calculates the lubounds of elements of x1 have the same 2nd, 3rd...nth
; indices. i.e. bounds by contracting over the first index.
;
if n_elements(all) ne 1 then all=0
if all eq 0 then begin
x=reform(x1)
end else begin
x=reform(x1, n_elements(x1))
end
sx=size(x)
if n_elements(ignore) eq 0 then begin
if sx(0) le 1 then begin
lub= [min(x), max(x)]
end else begin
nx=sx(2+sx(0))/sx(1)
lub=make_array(nx, 2, type=sx(sx(0)+1) )
x=reform(x, sx(1), nx)
for i=0l, nx-1 do begin
lub(i,*)=[min(x(*,i)), max(x(*,i)) ]
end
lub=reform(lub, [sx(2:sx(0)),2] )
end
end else begin
if sx(0) le 1 then begin
ips=where(x ne ignore)
if ips(0) ge 0 then begin
lub= [min(x(ips)), max(x(ips))]
end else begin
lub=replicate(ignore,2)
end
end else begin
nx=sx(2+sx(0))/sx(1)
lub=make_array(nx, 2, type=sx(sx(0)+1) )
x=reform(x, sx(1), nx)
for i=0l, nx-1 do begin
ips=where(x(*,i) ne ignore)
if ips(0) ge 0 then begin
lub(i,*)= [min(x(ips,i)), max(x(ips,i))]
end else begin
lub(i,*)=replicate(ignore,2)
end
end
lub=reform(lub, [sx(2:sx(0)), 2] )
end
end
return, lub
end
"Thomas C. Stubbings" wrote:
> What I would need is something like the MATLAB command max(i) where i is an
> array(n,m) and max(i) returns a vector containing the maximum value of each
> column. The IDL max command only returns a scalar containing the absolute
> maximum of the array.
>
> I even tried a big loop running through each column to find the max of each,
> but IDL doesnt accept loops with 64000 iterations
>
> What alternatives do I have?
>
> Thomas
|
|
|