Re: Question about the TOTAL function. [message #43539] |
Fri, 15 April 2005 09:38 |
Benjamin Hornberger
Messages: 258 Registered: March 2004
|
Senior Member |
|
|
Have a look at the "dimension" parameter of the TOTAL function. You need
to do
SUMX = TOTAL(matrix, 2)
or maybe 1 instead of 2 -- I didn't really understand which dimension
you want to sum over.
Benjamin
Nuno Oliveira wrote:
> I have a question that somebody that works with IDL many had faced before.
> Imagine I have a matrix(X,Y), no matter the type of variable, and if want na
> array with the projection along de x axis, something like
>
>
>
> for i = 0, n-1 do $
>
> SUMX = TOTAL(i, *)
>
>
>
> How can I do it without the FOR cicle.
>
>
>
> If I try
>
>
>
> SUMX[ 0:N-1 ] = TOTAL( 0:N-1, * )
>
>
>
> The function returns the total of the matrix for the every position of SUMX.
> Is there a way that I can do it quicker?
>
>
>
> Thanks in advance,
>
>
>
> Greeting,
>
>
>
> Nuno.
>
>
|
|
|
Re: Question about the TOTAL function. [message #43540 is a reply to message #43539] |
Fri, 15 April 2005 09:08  |
James Kuyper
Messages: 425 Registered: March 2000
|
Senior Member |
|
|
Nuno Oliveira wrote:
> I have a question that somebody that works with IDL many had faced before.
> Imagine I have a matrix(X,Y), no matter the type of variable, and if want na
> array with the projection along de x axis, something like
>
>
>
> for i = 0, n-1 do $
>
> SUMX = TOTAL(i, *)
; I presume you mean
sumx[i] = TOTAL(matrix[i,*])
> How can I do it without the FOR cicle.
sumx = TOTAL(matrix, 2)
; Similarly, if you want to calculate
sumy[j] = TOTAL(matrix[*,j])
; you can just use:
sumy = TOTAL(matrix,1)
|
|
|
Re: Question about the TOTAL function. [message #43541 is a reply to message #43540] |
Fri, 15 April 2005 09:05  |
rexford.newbould
Messages: 1 Registered: April 2005
|
Junior Member |
|
|
(Your question is actually pretty simple, so even I can field it.)
I think you're asking if you can sum along a single dimension in a
matrix, e.g.:
for i = 0, n-1 do $
SUMX = TOTAL(matrix[i,*])
If so, check the help for total. You can pass an optional argument
which is the dimension along which to sum.
SUMX = TOTAL(matrix,0)
SUMY = TOTAL(matrix,1)
Cheers,
Rex
Nuno Oliveira wrote:
> I have a question that somebody that works with IDL many had faced
before.
> Imagine I have a matrix(X,Y), no matter the type of variable, and if
want na
> array with the projection along de x axis, something like
>
>
>
> for i = 0, n-1 do $
>
> SUMX = TOTAL(i, *)
>
>
>
> How can I do it without the FOR cicle.
>
>
>
> If I try
>
>
>
> SUMX[ 0:N-1 ] = TOTAL( 0:N-1, * )
>
>
>
> The function returns the total of the matrix for the every position
of SUMX.
> Is there a way that I can do it quicker?
>
>
>
> Thanks in advance,
>
>
>
> Greeting,
>
>
>
> Nuno.
|
|
|