Got Questions? Get Answers.
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:
COV broken for vectors in r2011a

Subject: COV broken for vectors in r2011a

From: Richard Crozier

Date: 26 Sep, 2011 09:42:13

Message: 1 of 5

My department has just upgraded to r2011a

The cov function is supposed to take a vector and return the variance of the vector, but cov now contains this test at the start:

if ~ismatrix(x)
  error(message('MATLAB:cov:InputDim'));
end

This means vectors are always rejected. Aren't functions tested before deployment, or am I missing something here?

Consider the following in r2008a

>> indepvar = [1,2,3,4,5];
>> cov(indepvar)

ans =

    2.5000

But in r2011a:

K>> indepvar = [1,2,3,4,5];
K>> cov(indepvar)
??? Error using ==> cov at 37
Inputs must be 2-D.

Subject: COV broken for vectors in r2011a

From: Wayne King

Date: 26 Sep, 2011 10:15:15

Message: 2 of 5

"Richard Crozier" wrote in message <j5phdl$44a$1@newscl01ah.mathworks.com>...
> My department has just upgraded to r2011a
>
> The cov function is supposed to take a vector and return the variance of the vector, but cov now contains this test at the start:
>
> if ~ismatrix(x)
> error(message('MATLAB:cov:InputDim'));
> end
>
> This means vectors are always rejected. Aren't functions tested before deployment, or am I missing something here?
>
> Consider the following in r2008a
>
> >> indepvar = [1,2,3,4,5];
> >> cov(indepvar)
>
> ans =
>
> 2.5000
>
> But in r2011a:
>
> K>> indepvar = [1,2,3,4,5];
> K>> cov(indepvar)
> ??? Error using ==> cov at 37
> Inputs must be 2-D.

Hi Richard, I don't have any problem with this in R2011a
indepvar =[1,2,3,4,5];
ismatrix(indepvar)

ans =

     1

size(indepvar)

ans =

     1 5

cov(indepvar)

ans =

    2.5000


I suspect your installation has a non-Mathworks' version of ismatrix(). The Mathworks' version of ismatrix() returns a 1 for row and column vectors. If size() returns a row vector with nonnegative integers, then ismatrix() (the Mathworks' ismatrix()) is 1.

If you enter:

>>which ismatrix

Do you get something like this:
built-in (/mathworks...toolbox/matlab/elmat/ismatrix)

Wayne

Subject: COV broken for vectors in r2011a

From: Richard Crozier

Date: 26 Sep, 2011 10:25:13

Message: 3 of 5

"Wayne King" wrote in message <j5pjbj$a0o$1@newscl01ah.mathworks.com>...
> "Richard Crozier" wrote in message <j5phdl$44a$1@newscl01ah.mathworks.com>...
> > My department has just upgraded to r2011a
> >
> > The cov function is supposed to take a vector and return the variance of the vector, but cov now contains this test at the start:
> >
> > if ~ismatrix(x)
> > error(message('MATLAB:cov:InputDim'));
> > end
> >
> > This means vectors are always rejected. Aren't functions tested before deployment, or am I missing something here?
> >
> > Consider the following in r2008a
> >
> > >> indepvar = [1,2,3,4,5];
> > >> cov(indepvar)
> >
> > ans =
> >
> > 2.5000
> >
> > But in r2011a:
> >
> > K>> indepvar = [1,2,3,4,5];
> > K>> cov(indepvar)
> > ??? Error using ==> cov at 37
> > Inputs must be 2-D.
>
> Hi Richard, I don't have any problem with this in R2011a
> indepvar =[1,2,3,4,5];
> ismatrix(indepvar)
>
> ans =
>
> 1
>
> size(indepvar)
>
> ans =
>
> 1 5
>
> cov(indepvar)
>
> ans =
>
> 2.5000
>
>
> I suspect your installation has a non-Mathworks' version of ismatrix(). The Mathworks' version of ismatrix() returns a 1 for row and column vectors. If size() returns a row vector with nonnegative integers, then ismatrix() (the Mathworks' ismatrix()) is 1.
>
> If you enter:
>
> >>which ismatrix
>
> Do you get something like this:
> built-in (/mathworks...toolbox/matlab/elmat/ismatrix)
>
> Wayne

Ahh, you're right, there is a version of ismatrix on the system, I didn't know TMW had introduced this. I would have though ismatrix would return false for vectors though.

Subject: COV broken for vectors in r2011a

From: Wayne King

Date: 26 Sep, 2011 10:41:13

Message: 4 of 5

"Richard Crozier" wrote in message <j5pju9$bv1$1@newscl01ah.mathworks.com>...
> "Wayne King" wrote in message <j5pjbj$a0o$1@newscl01ah.mathworks.com>...
> > "Richard Crozier" wrote in message <j5phdl$44a$1@newscl01ah.mathworks.com>...
> > > My department has just upgraded to r2011a
> > >
> > > The cov function is supposed to take a vector and return the variance of the vector, but cov now contains this test at the start:
> > >
> > > if ~ismatrix(x)
> > > error(message('MATLAB:cov:InputDim'));
> > > end
> > >
> > > This means vectors are always rejected. Aren't functions tested before deployment, or am I missing something here?
> > >
> > > Consider the following in r2008a
> > >
> > > >> indepvar = [1,2,3,4,5];
> > > >> cov(indepvar)
> > >
> > > ans =
> > >
> > > 2.5000
> > >
> > > But in r2011a:
> > >
> > > K>> indepvar = [1,2,3,4,5];
> > > K>> cov(indepvar)
> > > ??? Error using ==> cov at 37
> > > Inputs must be 2-D.
> >
> > Hi Richard, I don't have any problem with this in R2011a
> > indepvar =[1,2,3,4,5];
> > ismatrix(indepvar)
> >
> > ans =
> >
> > 1
> >
> > size(indepvar)
> >
> > ans =
> >
> > 1 5
> >
> > cov(indepvar)
> >
> > ans =
> >
> > 2.5000
> >
> >
> > I suspect your installation has a non-Mathworks' version of ismatrix(). The Mathworks' version of ismatrix() returns a 1 for row and column vectors. If size() returns a row vector with nonnegative integers, then ismatrix() (the Mathworks' ismatrix()) is 1.
> >
> > If you enter:
> >
> > >>which ismatrix
> >
> > Do you get something like this:
> > built-in (/mathworks...toolbox/matlab/elmat/ismatrix)
> >
> > Wayne
>
> Ahh, you're right, there is a version of ismatrix on the system, I didn't know TMW had introduced this. I would have though ismatrix would return false for vectors though.

Hi Richard, ismatrix() was introduced in R2010b along with isrow() and iscolumn() that you can use for row or column vectors.

Hope that helps,
Wayne

Subject: COV broken for vectors in r2011a

From: Steven_Lord

Date: 26 Sep, 2011 13:14:01

Message: 5 of 5



"Richard Crozier" <r.crozier@ed.ac.uk> wrote in message
news:j5pju9$bv1$1@newscl01ah.mathworks.com...
> "Wayne King" wrote in message <j5pjbj$a0o$1@newscl01ah.mathworks.com>...
>> "Richard Crozier" wrote in message
>> <j5phdl$44a$1@newscl01ah.mathworks.com>...

*snip*

> Ahh, you're right, there is a version of ismatrix on the system, I didn't
> know TMW had introduced this. I would have though ismatrix would return
> false for vectors though.

As Wayne said these were introduced in release R2010b:

http://www.mathworks.com/help/techdoc/rn/bsk8h3i-1.html

I recommend that when you upgrade your version of MATLAB that you spend a
few minutes reviewing the Release Notes. We try to make sure that most or
all of the major changes to each product are mentioned there. The Release
Notes for releases back to R14 (which was released about seven years ago)
are available online; I believe there are also in the documentation included
in your installation.

http://www.mathworks.com/help/techdoc/rn/rn_intro.html

Looking specifically at ISMATRIX, these are the rules that the IS<array
shape> functions follow.

ISSCALAR returns true if calling SIZE on the input returns [1 1].
ISVECTOR returns true if calling SIZE on the input returns [1 n] or [n 1]
for nonnegative scalar n.
ISMATRIX returns true if calling SIZE on the input returns [m n] where m and
n are nonnegative scalars.
ISROW returns true if calling SIZE on the input returns [1 n] for
nonnegative scalar n.
ISCOLUMN returns true if calling SIZE on the input returns [n 1] for
nonnegative scalar n.

In particular, if x is a 1-by-1 array then all of isscalar(x), isvector(x)
[n = 1], ismatrix(x) [m, n = 1], isrow(x) [n = 1], and iscolumn(x) [n = 1]
are true. Since the SIZE of a vector is [1 n] or [n 1] it satisfies the
requirement for ISMATRIX.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for 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