[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: re: arrayfun on quaternion arrays
From: |
Markus Mützel |
Subject: |
Re: re: arrayfun on quaternion arrays |
Date: |
Sun, 7 Jun 2020 12:10:18 +0200 |
Am 07. Juni 2020 um 11:52 Uhr schrieb "octavecontrib":
> 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 mtimes
>
> arrayfun(@(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)
>
This is probably failing because the quaternion objects don't implement the
"numel" method correctly:
>> pkg load quaternion
>> qqq = [quaternion(1,0,0,0);
quaternion(1,0,0,0);
quaternion(2,0,0,0);];
>> numel(qqq)
ans = 1
I'd expect this to return 3 instead of 1.
The package hasn't been updated in a long time. But maybe you are lucky when
contacting the maintainer:
https://octave.sourceforge.io/quaternion/index.html
HTH,
Markus