2

I have an assignment like C = A(B) in a loop that size and shape of B change in every iteration. I need the size of C to be exactly like B. Documentation describes array indexing like this:

If you index into a vector with another vector, the orientation of the indexed vector is honored for the output

If you index into a vector with a nonvector, the shape of the indices is honored

So how can I keep shape and orientation of indices in both cases?

Community
  • 1
  • 1
saastn
  • 5,717
  • 8
  • 47
  • 78
  • 1
    That's annoying sometimes, isn't it? A solution is to apply `C = reshape(C, size(B));` afterwards – Luis Mendo Jan 23 '17 at 21:56
  • @LuisMendo It really is. Are there any other options? I need it to be as fast as possible, since `A` and `B` are both relatively large and for-loop may cycle more than 100K times... – saastn Jan 23 '17 at 22:03
  • 3
    Quite probably, that `reshape` [will not increase](http://stackoverflow.com/q/36062574/2586922) running time significantly – Luis Mendo Jan 23 '17 at 22:08

0 Answers0