Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab Error: Undefine Variable

  1. Nov 3, 2009 #1
    Hi,

    I am trying to model a simple 1DOF suspension system [mass(ms) 300kg, stiffness(k) 15000N/m, damping coefficient(c) 2500Ns/m. Its subjected to different inputs and then needs to simulate the dynamic response of the system to a road surface that has the characteristics of a flat road, a sine wave surface and then a step.

    I completed the model. However, i have now opened the file again and i keep getting the error message:

    Error evaluating parameter 'Numerator' in 'HC1/Transfer Fcn': Undefined function or variable 'c'

    I have defined "c" as 2500 in the "m" file and the matlab working directory is correct as far as i know. I have attached a screen shot of the error. Does any1 know how to solve this problem?
     

    Attached Files:

  2. jcsd
  3. Nov 3, 2009 #2

    Mark44

    Staff: Mentor

    I can't tell much from your screen shot. Can you show us your code for 'HC1/Transfer Fcn'? One possible reason for your problem is that you might be using c as if it were a global variable, but it's not. If c is defined in one function and you attempt to use it in another function, I think you will get the error you showed.

    If you want to be able to use c in all your functions, make it a global variable. Here is some info about global variables from the online Getting Started documentation for MatLab (http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/getstart.pdf)

    Global Variables
    If you want more than one function to share a single copy of a variable, simply
    declare the variable as global in all the functions. Do the same thing at
    the command line if you want the base workspace to access the variable.
    The global declaration must occur before the variable is actually used in a
    function. Although it is not required, using capital letters for the names of
    global variables helps distinguish them from other variables. For example,
    create an M-file called falling.m:
    function h = falling(t)
    global GRAVITY
    h = 1/2*GRAVITY*t.^2;
    Then interactively enter the statements
    global GRAVITY
    GRAVITY = 32;
    y = falling((0:.1:5)');

    The two global statements make the value assigned to GRAVITY at the
    command prompt available inside the function. You can then modify GRAVITY
    interactively and obtain new solutions without editing any files.
     
  4. Nov 5, 2009 #3
    Hi,

    Sorry for the late reply, i have been caught up doing other coursework. I have provided a screen shot of the code for "'HC1/Transfer Fcn"

    I will look into changing the global variable. Thanks
     

    Attached Files:

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Matlab Error: Undefine Variable
  1. Matlab Error (Replies: 1)

Loading...