[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how do I vectorize this?
From: |
Claudio Belotti |
Subject: |
Re: how do I vectorize this? |
Date: |
Fri, 14 Apr 2006 10:52:18 +0200 |
User-agent: |
Mutt/1.5.11+cvs20060126 |
Hi Brendan,
thank you for your reply. This is not really what I need as my data are
ungridded I don't think it would be convinient to organize them in a matrix.
now, I have something like that
z = [10; 20; 30; 40; 50]
using lookup I found
zidx = [ 1; 3; 3; 2; 4]
these are the indexes of the matrix zi (2x2)
if I do
zi(zidx)=z
I get zi = [10 30; 40 50]
(the 3rd value of z overwrites the 2nd one)
and I'm trying to get
zi = [10 25; 40 50]
(2nd+3rd)/2
as I wrote I do it with a for loop but I'm sure there is a better way...
thank you
Claudio
Thursday, 13 April 2006 Brendan Drew:
> You could do something like this:
>
> F = ones(n) ./ (n.^2); // create an n x n averaging filter
> zi = filter2(F, data);
>
> This treats your data as a 2D signal and applies an n x n averaging
> filter (at location (i, j), you have the average over the block (i-n/2,
> j-n/2), (i+n/2, j+n/2)).
>
> Hope this helps.
>
> Claudio Belotti wrote:
>
> >Dear all,
> >I have a set of values z spread over an x-y plane
> >I want to average the values on a fixed grid (xi,yi).
> >
> >I use:
> >xidx = lookup(xi,x)
> >yidx = lookup(yi,y)
> >zidx = sub2ind(sizeofgrid, xidx, yidx)
> >
> >and then
> >
> >for i=1:length(zidx)
> >zi( zidx(i)) += z(i)
> >ni( zidx(i)) += 1
> >endfor
> >zi = zi./ni
> >
> >my question is: how do I vectorize the for-loop above?
> >
> >cheers
> >Claudio
> >
> >
> >
>
>
> --
> Brendan Drew
> Research Scientist
> PercepTek, Inc.
> Tel: 720-344-1037 x 126
> Fax: 720-344-2360
> 12395 North Mead Way
> Littleton, CO 80125
>
-------------------------------------------------------------
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
-------------------------------------------------------------
- how do I vectorize this?, Claudio Belotti, 2006/04/13
- Message not available
- Re: how do I vectorize this?,
Claudio Belotti <=
- Re: how do I vectorize this?, Miroslaw Kwasniak, 2006/04/14
- Re: how do I vectorize this?, Claudio Belotti, 2006/04/14
- Re: how do I vectorize this?, John W. Eaton, 2006/04/14
- Re: how do I vectorize this?, Etienne Grossmann, 2006/04/14
- Re: how do I vectorize this?, Claudio Belotti, 2006/04/14