[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
find and indexing fun (was Re: Efficient Octave Code)
From: |
Joan Picanyol i Puig |
Subject: |
find and indexing fun (was Re: Efficient Octave Code) |
Date: |
Mon, 23 Oct 2006 01:40:07 +0200 |
User-agent: |
Mutt/1.5.11 |
* Bill Denney <address@hidden> [20061021 16:31]:
> rockster8 wrote:
> > for i=1:50
> > for j=1:50
> > for k=1:10
> > Fk(i,j) = F(i,j) .* (w(i,j) == k);
> > end
> > end
> > end
> >
> > where the following are initialized as:
> > Fk(1:50,1:50) = 0;
> > F(1:50,1:50) = 0;
> > w(1:50,1:50) = randomly generated numbers..
> >
> Well, first off, since you're multiplying 0 (F) times a boolean, Fk will
> always be zero, so
>
> Fk = zeros (size (F));
>
> would work. Assuming that F weren't 0, you could do something like this:
>
> for k = 1:10
> mask = (w == k);
> Fk(mask) = F(mask);
> endfor
How do you do that for more than one dimension? I have the following
piece of code, from which I don't know how to get the for loops out:
% flatten out pcsi's 3rd dimension (input channels) by vertical
% concatenation
lcsi = zeros (ln_taps * ln_input_channels, ln_OFDM_symb);
for li = 1:ln_input_channels
lidx = 1:ln_taps;
lidx = lidx + repmat (ln_taps * (li - 1), 1, ln_taps),
lcsi (lidx,:) = pcsi(:,:,li);
end
lcsi,
% flatten out ptaps' 2nd dimension (input channels) by vertical
% concatenation
ltaps = reshape(ptaps.', ln_echoes * ln_input_channels, 1);
lchannels = repmat(ltaps, 1, ln_OFDM_symb),
% apply CSI to channels
% funny indexing caused by weird find behaviour
lchannels(lchannels ~= 0) = lchannels(lchannels ~= 0) .* lcsi(find (lcsi)),
lchannel = zeros (ln_echoes, ln_OFDM_symb);
for li = 1:ln_input_channels
lidx = 1:ln_echoes;
lidx = lidx + repmat (ln_echoes * (li - 1), 1, ln_echoes);
lchannel(:,:) = lchannel + lchannels(lidx,:);
end
lchannel = lchannel / ln_input_channels,
For those in communications, this should equalize an OFDM signal through
a MISO channel (but it doesn't).
tks
--
pica