Tags: appeared, attemptto, compile, error, function, m-file, matlab, programming, runtime, variable

Error: Previously used as a function

On Programmer » Matlab

4,390 words with 5 Comments; publish: Sun, 27 Apr 2008 05:18:00 GMT; (20062.01, « »)

I have an M-file with a variable called 'runtime', and when I attempt

to compile it, I get this error:

"runtime" previously appeared to be used as a function or command,

conflicting with its use here as the name of a variable. A possible

cause of this error is that you forgot to initialize the variable, or

you have initialized it implicitly using load or eval.

However, I don't use it as a function or command, and I initialized

it in the main function. (I even made it a global variable.)

What's more is that I haven't changed the use of that variable, but

it worked in R2006a. This makes me think it does have something to do

with the new prevention of using it as a variable and function, but

again, I don't use it as such.

All Comments

Leave a comment...

  • 5 Comments
    • In article <ef5cfb6.-1.matlab.todaysummary.com.webcrossing.raydaftYaTP>, mak5139.matlab.todaysummary.com.psu.REMOVE.edu

      says...

      > I have an M-file with a variable called 'runtime', and when I attempt

      > to compile it, I get this error:

      > "runtime" previously appeared to be used as a function or command,

      > conflicting with its use here as the name of a variable. A possible

      > cause of this error is that you forgot to initialize the variable, or

      > you have initialized it implicitly using load or eval.

      > However, I don't use it as a function or command, and I initialized

      > it in the main function. (I even made it a global variable.)

      > What's more is that I haven't changed the use of that variable, but

      > it worked in R2006a. This makes me think it does have something to do

      > with the new prevention of using it as a variable and function, but

      > again, I don't use it as such.

      >

      Did you declare runtime global in all the functions that use it, not

      just the main one?

      FYI, there are probably better ways to accomplish your task than using

      global variables, if you could describe that to the group.

      -- Loren

      http://blogs.mathworks.com/loren/

      #1; Sun, 27 Apr 2008 05:20:00 GMT
    • Loren Shure wrote:

      > Did you declare runtime global in all the functions that use it,

      > not

      > just the main one?

      > FYI, there are probably better ways to accomplish your task than

      > using

      > global variables, if you could describe that to the group.

      > -- Loren

      > <http://blogs.mathworks.com/loren/>

      >

      Ah, I didn't declare it global in all the functions that use it. I'll

      try that.

      There probably are better ways than global variables, too. I know, I

      feel bad for using them. All I really need to do is let multiple

      functions access and alter the variable.

      #2; Sun, 27 Apr 2008 05:21:00 GMT
    • In article <ef5cfb6.1.matlab.todaysummary.com.webcrossing.raydaftYaTP>, mak5139.matlab.todaysummary.com.psu.REMOVE.edu

      says...

      > Loren Shure wrote:

      > Ah, I didn't declare it global in all the functions that use it. I'll

      > try that.

      > There probably are better ways than global variables, too. I know, I

      > feel bad for using them. All I really need to do is let multiple

      > functions access and alter the variable.

      >

      Look into nested functions, especially if they are already all in the

      same file.

      -- Loren

      http://blogs.mathworks.com/loren/

      #3; Sun, 27 Apr 2008 05:22:00 GMT
    • > Look into nested functions, especially if they are already all in

      > the

      > same file.

      > -- Loren

      > <http://blogs.mathworks.com/loren/>

      It's been a while since I last looked at this code, and looking at it

      closer after the last error I got, I realized I did use nested

      functions. Given that, I think the problem might have been that I did

      try to declare it global.

      - Michael

      #4; Sun, 27 Apr 2008 05:23:00 GMT
    • OK, even using nested functions, I still get the warning "runtime can

      apparently be used before it is defined" when it is defined in the

      outermost function. I have this problem with another variable, as

      well, and I get the runtime error that it is undefined.

      #5; Sun, 27 Apr 2008 05:24:00 GMT