0

This related question How can I apply a function to every row/column of a matrix in MATLAB? seems to indicate one way to do this is using num2cell, which I kind of want to stay away from.

Here's what I want to do. I've got an index list for a triangle mesh, the indices index the vertex list.

I want to run func(a,b,c) on the first 3 indices, then the next three indices, and so on.

So I could reshape(idxs,3,[]) so now i've got my data into triplets as column vectors. But arrayfun does not do what I want it to do.

Looking for something like a column-map operator.

Community
  • 1
  • 1
Steven Lu
  • 41,389
  • 58
  • 210
  • 364

1 Answers1

2

First, get your func properly vectorized, if necessary, such that the arguments can be lists of equal length:

vec_func = @(a,b,c)(arrayfun(@func,a,b,c))

Then, you can directly access every third element of idxs:

vec_func( idxs(1:3:end), idxs(2:3:end), idxs(3:3:end) )
user57368
  • 5,675
  • 28
  • 39