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.

1 Answer 1

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) ) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.