performance - arrayfun 2d matrix input -
i have 3d matrix (8x5x100) containing numerical data. need pass 2d matrix (8x5) taken 3d matrix function , repeat process 100 times(length of 3d matrix). goal speed process as possible. sorry, cannot post actual code.
current code:
3dmatrix=ones(8,5,100); i=1:100 output(i)=subfunction(3dmatrix(:,:,i)); end
i read using arrayfun may faster looping. correct implementation?
3dmatrix=ones(8,5,100); i=1:100 output(i)=arrayfun(@(x) subfunction(x),3dmatrix(:,:,i)); end
when try execute code using new method, keep getting errors in "subfunction" code. in "subfunction", uses size of 2d matrix calculations. however, when use arrayfun method, keeps reading size 1x1 instead of 8x5, causing rest of code crash, complaining not being able access parts of vectors since not calculated due size discrepancy. passing in matrix correctly?
what correct way of going speed being imperative? thanks!
did @ arrayfun documentation? don't think need use loop when using arrayfun
. have considered using parfor
loops? use them make code faster too..
3dmatrix=ones(8,5,100); parfor i=1:100 output(i)=arrayfun(@(x) subfunction(x),3dmatrix(:,:,i)); end
Comments
Post a Comment