X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fquaternion-2.0.0%2F%40quaternion%2Fsubsasgn.m;fp=octave_packages%2Fquaternion-2.0.0%2F%40quaternion%2Fsubsasgn.m;h=8777b5c986d97093397f8a020d201ea1ae66e77a;hp=0000000000000000000000000000000000000000;hb=f5f7a74bd8a4900f0b797da6783be80e11a68d86;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/quaternion-2.0.0/@quaternion/subsasgn.m b/octave_packages/quaternion-2.0.0/@quaternion/subsasgn.m new file mode 100644 index 0000000..8777b5c --- /dev/null +++ b/octave_packages/quaternion-2.0.0/@quaternion/subsasgn.m @@ -0,0 +1,64 @@ +## Copyright (C) 2011 Lukas F. Reichlin +## +## This program is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program. If not, see . + +## -*- texinfo -*- +## Subscripted assignment for quaternions. +## Used by Octave for "q.key = value". + +## Author: Lukas Reichlin +## Created: November 2011 +## Version: 0.2 + +function q = subsasgn (q, idx, val) + + switch (idx(1).type) + case "()" # q(...) = val + if (length (idx(1).subs) == 1 && isa (val, "quaternion")) # required by horzcat, vertcat, cat, ... + q(idx(1).subs{:}) = val; # q = cellfun (@quaternion, varargin) + else # general case + val = quaternion (val); + w = subsasgn (q.w, idx, val.w); + x = subsasgn (q.x, idx, val.x); + y = subsasgn (q.y, idx, val.y); + z = subsasgn (q.z, idx, val.z); + q = quaternion (w, x, y, z); + endif + + case "." # q.w = val + if (! is_real_array (val)) + error ("quaternion: subsasgn: invalid argument type, require real array"); + endif + if (! size_equal (subsref (q.w, idx(2:end)), val)) + error ("quaternion: subsasgn: invalid argument size [%s], require dimensions [%s]", \ + num2str (size (val), "%d "), num2str (size (subsref (q.w, idx(2:end))), "%d ")); + endif + switch (tolower (idx(1).subs)) + case {"w", "s"} + q.w = subsasgn (q.w, idx(2:end), val); + case {"x", "i"} + q.x = subsasgn (q.x, idx(2:end), val); + case {"y", "j"} + q.y = subsasgn (q.y, idx(2:end), val); + case {"z", "k"} + q.z = subsasgn (q.z, idx(2:end), val); + otherwise + error ("quaternion: subsasgn: invalid subscript name '%s'", idx(1).subs); + endswitch + + otherwise + error ("quaternion: subsasgn: invalid subscript type '%s'", idx(1).type); + endswitch + +endfunction