Question

This might be something silly, but basically, I have a function in MATLAB called wavedec. This function does a wavelet decomposition of a vector.

Now, looking at the documentation, the input of this function must be a vector.

However, what if I have a matrix, and I want to call this function for each column of the matrix? Worst case I can put it into a for-loop, but I was wondering if there was a more elegant way. (Maybe with arrayfun? I dont know).

Thanks.

Was it helpful?

Solution

It is possible using cellfun, you have to convert the matrix to a cell of vectors:

mat2cell(M,size(M,1),ones(size(M,2),1))

Both, cellfun and arrayfun internally work iterative, which means it's not faster than a for loop.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top