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:
Problem with Null

Subject: Problem with Null

From: Jessica

Date: 3 Oct, 2009 20:01:02

Message: 1 of 6

Hi,

I am trying to create an empty column. When I do so, I type in:

NewColumn=null(:,30);

And get the error:
??? At compilation, "null" was determined to be a variable and this
 variable is uninitialized. "null" is also a function name and previous versions of MATLAB would have called the function.
 However, MATLAB 7 forbids the use of the same name in the same
 context as both a function and a variable.


Does anyone know how to get around this problem? This function used to work on my computer but suddenly does not. Thanks!

Subject: Problem with Null

From: dpb

Date: 3 Oct, 2009 20:55:13

Message: 2 of 6

Jessica wrote:
> Hi,
>
> I am trying to create an empty column. When I do so, I type in:
>
> NewColumn=null(:,30);
>
> And get the error:
> ??? At compilation, "null" was determined to be a variable and this
> variable is uninitialized. "null" is also a function name and
> previous versions of MATLAB would have called the function.
> However, MATLAB 7 forbids the use of the same name in the same
> context as both a function and a variable.
>
>
> Does anyone know how to get around this problem? This function used
> to work on my computer but suddenly does not. Thanks!

What problem, specifically? Don't do that; even in older versions
overriding builtin ML functions w/ variables is universally not a good
idea. There are any number of posts here of bizarre symptoms whose root
cause is having done just that.

If you want a null variable, name it something other than null,
specifically.

--

Subject: Problem with Null

From: ImageAnalyst

Date: 4 Oct, 2009 00:58:23

Message: 3 of 6

On Oct 3, 4:01 pm, "Jessica" <jyorzin...@ucdavis.edu> wrote:
> Hi,
>
> I am trying to create an empty column. When I do so, I type in:
>
> NewColumn=null(:,30);
>
> And get the error:
> ??? At compilation, "null" was determined to be a variable and this
>  variable is uninitialized.  "null" is also a function name and previous versions of MATLAB would have called the function.
>  However, MATLAB 7 forbids the use of the same name in the same
>  context as both a function and a variable.
>
> Does anyone know how to get around this problem? This function used to work on my computer but suddenly does not. Thanks!
--------------------------------------------------------------------
Jessica:

Why do you want to do this? Null columns get removed. Look at this
a=magic(3)
a(:,2) = [] % Get rid of middle column
When the first line executes, a is a 3 by 3 matrix. When the second
line executes, it turns it into a 3 row by 2 column matrix.
NaN's don't get removed:
a(:,2) = nan % Still a 3 by 2 matrix but with all nan's in the second
column.
Maybe you want to create a NewColumn variable with all nan's. I'm not
really sure what your final aim is. How will you use NewColumn after
you've created it?

Subject: Problem with Null

From: Jessica

Date: 4 Oct, 2009 01:14:02

Message: 4 of 6

I'm just trying to create an empty column of a certain length. Then, with a loop, I can add numbers to this column one-by-one.

Subject: Problem with Null

From: James Tursa

Date: 4 Oct, 2009 06:33:17

Message: 5 of 6

"Jessica" <jyorzinski@ucdavis.edu> wrote in message <ha8ssq$g74$1@fred.mathworks.com>...
> I'm just trying to create an empty column of a certain length. Then, with a loop, I can add numbers to this column one-by-one.

That's pre-allocation. Don't create an empty column. Instead, create a column of zeros to start with.

James Tursa

Subject: Problem with Null

From: Jan Simon

Date: 4 Oct, 2009 07:36:01

Message: 6 of 6

Dear Jessica!

> I am trying to create an empty column. When I do so, I type in:
>
> NewColumn = null(:,30);
>
> Does anyone know how to get around this problem? This function used to work on my computer but suddenly does not. Thanks!

I cannot imagine, that the above call has worked ever to create a vector without elements. If your "null" was a function, it should fail, because ":" is not a valid input. If your "null" was a variable, "null(:, 30)" copies the 30.th column, but not an empty one.

I assume, you are looking for:
  NewColumn = zeros(30, 0);
This is an empty column vector with(out) 30 elements.
As James states already, concatenation of arrays in a for loop is really ineffective. If you show us the loop, we could give more detailed recommendations.

Good luck, Jan

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