help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [OctDev] Access struct fields inside cell


From: Lukas Reichlin
Subject: Re: [OctDev] Access struct fields inside cell
Date: Sat, 15 May 2010 12:58:07 +0200

On 15.05.2010, at 07:03, Jaroslav Hajek wrote:

> On Fri, May 14, 2010 at 11:37 PM, Lukas Reichlin
> <address@hidden> wrote:
>> Dear Octave Community
>> 
>> I have a struct "quaternion" with fields w, x, y and z. The fields are 
>> matrices.
>> 
>> Next I build a cell array "qcell" which contains quaternions.
>> 
>> Now I can access fields with   qcell{2}.w
>> 
>> However,    qcell{:}.w     doesn't seem to work.
>> 
>> How can I extract those fields? Thanks for every help!
>> 
> 
> Basically, you can't. There is no simple way. Instead of building a
> cell array of scalar structs, it's better to build a non-scalar
> struct:
> 
> qstr = cellfun (@quaternion, varargin);  # uniformoutput = true !
> 
> w = horzcat (qstr.w);
> x = horzcat (qstrl.x);
> y = horzcat (qstr.y);
> z = horzcat (qstr.z);
> 
> 
> -- 
> RNDr. Jaroslav Hajek, PhD
> computing expert & GNU Octave developer
> Aeronautical Research and Test Institute (VZLU)
> Prague, Czech Republic
> url: www.highegg.matfyz.cz

Thank you, Jaroslav. Your code works as expected.

I noticed a problem with the three lines of code below:

q = quaternion (1, 2, 3, 4)
[q, 5]  # works as expected
q  # q is corrupted now

Quaternion q should stay unaltered, but somehow it got corrupted by horzcat. 
I'm using Octave 3.2.4 from MacPorts. Probably this issue is related to this 
bug [1] which was fixed for 3.3.51. Unfortunately, I'm unable to build 
development versions on my Mac. Therefore it would be good if someone could 
test whether the problem is solved for 3.3.51+. The attachment contains an 
early version (not even published in OctaveForge's repository) of a quaternion 
package with some overloaded operators.

Best regards,
Lukas

[1]
https://www-old.cae.wisc.edu/pipermail/bug-octave/2009-November/009696.html


Attachment: quaternion_oo.zip
Description: Zip archive


reply via email to

[Prev in Thread] Current Thread [Next in Thread]