Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
check matrix size

Subject: check matrix size

From: Kirk

Date: 11 Jan, 2007 21:18:41

Message: 1 of 4

The following line give me an error. How do I correct this? I don't
want an if inside another if, too ugly...

if size(relph)~=[1,4] && size(relph)~=[4,1]
...
end

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

Subject: check matrix size

From: Dan Hensley

Date: 11 Jan, 2007 23:32:22

Message: 2 of 4

On Thu, 11 Jan 2007 21:18:41 -0500, kirk wrote:

> The following line give me an error. How do I correct this? I don't
> want an if inside another if, too ugly...
>
> if size(relph)~=[1,4] && size(relph)~=[4,1]
> ...
> end
>
> ??? Operands to the || and && operators must be convertible to
> logical scalar values.

Why don't you stop just before this statement in the debugger, and see
what size(relph)~=[1,4] gives you? That will explain the error.

To correct it, try

help isequal

Dan

Subject: check matrix size

From: Pedro Villena

Date: 12 Jan, 2007 05:22:21

Message: 3 of 4

Hi,

SOLUTION 1:
You have to use a Element-wise Logical Operator.

Short-circuit logical AND &&
Element-wise logical AND &

result = size(relph)~=[1,4] & size(relph)~=[4,1];
if result(1) && result(2)

SOLUTION 2:
You can use the ANY Function, and a Element-wise Logical Operator.

all - True if all elements of a vector are nonzero

if all(size(relph)~=[1,4] & size(relph)~=[4,1])

Subject: check matrix size

From: John D'Errico

Date: 12 Jan, 2007 05:44:38

Message: 4 of 4

In article <ef4ae14.-1@webcrossing.raydaftYaTP>, kirk <kirkvon@hotmail.com> wrote:

> The following line give me an error. How do I correct this? I don't
> want an if inside another if, too ugly...
>
> if size(relph)~=[1,4] && size(relph)~=[4,1]
> ...
> end
>
> ??? Operands to the || and && operators must be convertible to
> logical scalar values.

if ~isvector(relph) || (length(relph)~=4)
   error 'Help, the sky is falling, the sky is falling!!!!!!'
end

HTH,
John


--
The best material model of a cat is another, or preferably the same, cat.
A. Rosenblueth, Philosophy of Science, 1945

Those who can't laugh at themselves leave the job to others.
Anonymous

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us