arrayfun (@(x) abs(x), qqq, "uni", 0)
ans =
{
[1,1] =
1
1
}
## (some people prefer '"UniformOutput", false')
Is this the result you want?
- Is there a way to directly get a matrix as output rather than as a cell array?
Since each application of the anonymous function returned the same datatype (double) with the same size (1x1), I expected UniformOutput=true would have worked. I would like to know why it didn't.
- Also it looks like the array function executes the anonymous function only ONE time instead of length(qqq) times as shown by the code below. In my actual code I want the anonymous function to be called length(qqq) times as the actual function is more complicated than the example.
qqq = [quaternion(1,0,0,0);
quaternion(1,0,0,0);
quaternion(2,0,0,0);];
%
qqq(1) * [1;2]
% this line works when ONE quaternion is passed to mtimesarrayfun(@(x)[1; 2], qqq, 'UniformOutput', false)
% this line indicates that the anonymous function is called only once.arrayfun(@(x)x*[1; 2], qqq, 'UniformOutput', false) % this line throws an error as the total quaternion array is passed as such to the anonymous function.
Output
=====
ans.w =
1
2
ans.x =
0
0
ans.y =
0
0
ans.z =
0
0
ans =
{
[1,1] =
1
2
}
error: mtimes: operator *: nonconformant arguments (op1 is 3x1, op2 is 2x1)