1

I have a matrix, say:

y=rand(100,101);

Now I would like to average over the first dimension, and use only part of the output (say only the odd indices) into another function. So I could do

ymean=mean(y,1)

and then

ymean_partial=somefunction(ymean(1:2:length(ymean)))

But my question now is (assuming it is possible): how can I do this without having to declare the 'dummy variable' ymean? I would like to know if there's a one-liner I could use, since this extra variable takes up a lot of memory for larger matrices (and I tend to like one-liners).

Many thanks!

Jonas
  • 74,690
  • 10
  • 137
  • 177
Fraukje
  • 673
  • 3
  • 20
  • 1
    Please see this related question: http://stackoverflow.com/questions/3627107/how-can-i-index-a-matlab-array-returned-by-a-function-without-first-assigning-it – H.Muster Sep 05 '13 at 09:57
  • Oh great, that's actually the general solution I was looking for, although Jonas' answer works perfectly in this case. – Fraukje Sep 05 '13 at 10:02

1 Answers1

6

Why don't you simply take the mean on the subset only?

ymean_subset = mean(y(:,1:2:end),1);
Jonas
  • 74,690
  • 10
  • 137
  • 177