From: Yukiko Shimizu on
This is my code

y=size(C);
u=[4 1];
if y(1:1)~=u(1:1) || y(1:2)~=u(1:2)%any(y)~=size([0;0;0;0]),
error('MATLAB:quat2angle:InputSizeMismatch','C must be a 4x1 matrix.');
end

When I run: quat2angle([4;3;4;0]) I get:

??? Operands to the || and &&
operators must be convertible to
logical scalar values.

Error in ==> quat2angle at 14
if y(1:1)~=u(1:1) &&
y(1:2)~=u(1:2)%any(y)~=size([0;0;0;0]),

If I run quat2angle([4;4;4]) I do correctly get the expected error.

Why isn't it working for when the equality is true? (quat2angle([4;3;4;0]))
From: Frédéric Bergeron on
"Yukiko Shimizu" <yk.mizu(a)gmail.com> wrote in message <hvqngh$pls$1(a)fred.mathworks.com>...
> This is my code
>
> y=size(C);
> u=[4 1];
> if y(1:1)~=u(1:1) || y(1:2)~=u(1:2)%any(y)~=size([0;0;0;0]),
> error('MATLAB:quat2angle:InputSizeMismatch','C must be a 4x1 matrix.');
> end
>
> When I run: quat2angle([4;3;4;0]) I get:
>
> ??? Operands to the || and &&
> operators must be convertible to
> logical scalar values.
>
> Error in ==> quat2angle at 14
> if y(1:1)~=u(1:1) &&
> y(1:2)~=u(1:2)%any(y)~=size([0;0;0;0]),
>
> If I run quat2angle([4;4;4]) I do correctly get the expected error.
>
> Why isn't it working for when the equality is true? (quat2angle([4;3;4;0]))


Why don't you just write:
if any(y~=u)
error...
end
Fred
From: Yukiko Shimizu on
"Frédéric Bergeron" <frederic.bergeron(a)logiag.com> wrote in message <hvqoal$iju$1(a)fred.mathworks.com>...
> "Yukiko Shimizu" <yk.mizu(a)gmail.com> wrote in message <hvqngh$pls$1(a)fred.mathworks.com>...
> > This is my code
> >
> > y=size(C);
> > u=[4 1];
> > if y(1:1)~=u(1:1) || y(1:2)~=u(1:2)%any(y)~=size([0;0;0;0]),
> > error('MATLAB:quat2angle:InputSizeMismatch','C must be a 4x1 matrix.');
> > end
> >
> > When I run: quat2angle([4;3;4;0]) I get:
> >
> > ??? Operands to the || and &&
> > operators must be convertible to
> > logical scalar values.
> >
> > Error in ==> quat2angle at 14
> > if y(1:1)~=u(1:1) &&
> > y(1:2)~=u(1:2)%any(y)~=size([0;0;0;0]),
> >
> > If I run quat2angle([4;4;4]) I do correctly get the expected error.
> >
> > Why isn't it working for when the equality is true? (quat2angle([4;3;4;0]))
>
>
> Why don't you just write:
> if any(y~=u)
> error...
> end
> Fred

when I do that, I get

>> quat2angle([4;3;4:3],'xya')
??? Error using ==> quat2angle at 15
C must be a 4x1 matrix.

which is wrong because it should be equal. size ([4;3;4;3]) does equal u (4 1)
From: someone on
"Yukiko Shimizu" <yk.mizu(a)gmail.com> wrote in message <hvqngh$pls$1(a)fred.mathworks.com>...
> This is my code
>
> y=size(C);
> u=[4 1];
> if y(1:1)~=u(1:1) || y(1:2)~=u(1:2)%any(y)~=size([0;0;0;0]),
> error('MATLAB:quat2angle:InputSizeMismatch','C must be a 4x1 matrix.');
> end
>
> When I run: quat2angle([4;3;4;0]) I get:
>
> ??? Operands to the || and &&
> operators must be convertible to
> logical scalar values.
>
> Error in ==> quat2angle at 14
> if y(1:1)~=u(1:1) &&
> y(1:2)~=u(1:2)%any(y)~=size([0;0;0;0]),
>
> If I run quat2angle([4;4;4]) I do correctly get the expected error.
>
> Why isn't it working for when the equality is true? (quat2angle([4;3;4;0]))

Well, obviously in:

if y(1:1)~=u(1:1) || y(1:2)~=u(1:2)%any(y)~=size([0;0;0;0]),

y(1:2) and u(1:2) are NOT scalars in general
From: Steven Lord on

"Yukiko Shimizu" <yk.mizu(a)gmail.com> wrote in message
news:hvqngh$pls$1(a)fred.mathworks.com...
> This is my code
> y=size(C);
> u=[4 1];
> if y(1:1)~=u(1:1) || y(1:2)~=u(1:2)%any(y)~=size([0;0;0;0]),
> error('MATLAB:quat2angle:InputSizeMismatch','C must be a 4x1 matrix.');
> end
>
> When I run: quat2angle([4;3;4;0]) I get:
>
> ??? Operands to the || and &&
> operators must be convertible to
> logical scalar values.
>
> Error in ==> quat2angle at 14
> if y(1:1)~=u(1:1) &&
> y(1:2)~=u(1:2)%any(y)~=size([0;0;0;0]),
> If I run quat2angle([4;4;4]) I do correctly get the expected error.
>
> Why isn't it working for when the equality is true?
> (quat2angle([4;3;4;0]))

The error you receive is correct. As the error message indicates, the ||
and && operators require their inputs to be SCALAR logical values (or the
inputs must be convertible to scalar logical values, so 1 || true would work
since 1 can be converted to logical(1).) The expression "y(1:2) ~= u(1:2)"
returns a 1-by-2 logical array; a 1-by-2 array is NOT scalar. That is the
cause for the error in the case where y has 4 rows.

The reason you did NOT receive the error when y did not have 4 rows is
because || and && short-circuit. Basically, MATLAB executed the comparison:

y(1:1) ~= u(1:1)

and found that comparison to be true. Since or(true, <either true or
false>) is true, the whole expression is true and MATLAB does not need to
execute the second part of the expression. Similarly, if you had false &&
<some expression> then since and(false, <either true or false>) is false,
MATLAB does not need to execute the second piece to know the whole
expression will be false.

In this case, what you've done is NOT sufficient to ensure that C is a
4-by-1 vector. For example, the following C will pass your test while not
being a 4-by-1 vector:

C = zeros(4, 1, 2, 3, 4, 5);

Instead, if you want to make sure that C is EXACTLY a 4-by-1 vector, use
ISEQUAL.

if ~isequal(size(C), [4 1])
error(...)
end

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com