I need to perform an exponential operation with two parameters (one set: t, and the other from arrays) on a set of 2D arrays (if you want, a 3D matrix). f (t, x) = exp (tx) And then I need to add the result of each value in the 3rd dimension. Since it takes a long time to complete the whole operation bsxfun, I was thinking about using a lookup table.
I can create the table as a matrix LUT(two-dimensional due to two parameters), then I can get the values with LUT(par1,par2). But access to the 3rd dimension using a cycle is also expensive.
My question is: is there a way to implement such a mechanism (lookup table) to have predefined values, and then just use them to access the matrix elements (kind of indexing) without loops. Or, how can I create a lookup table that MATLAB automatically performs to speed up the exponential operation?
EDIT: I actually used similar methods to create the LUT. Now my problem is how to access it in an efficient way.
Lets say I have a 2 dimensional array M. With the values that I want to apply to the function f(t,M(i,j))for a fixed value t. I can use a loop to go through all the values of (i, j) M. But I need a faster way to do this, because I have a set of M, and then I need to apply this procedure to all the other values.
My function is a bit more complicated than the example I gave:
pr = mean(exp(-bsxfun(@rdivide,bsxfun(@minus,color_vals,double(I)).^2,m)./2),3);
This is my actual function, as you can see, more complex than the example I presented. But the idea is the same. It has an average value in the third dimension of the set M of the exponent of the difference of two arrays.
Hope this helps.