Matlab Error: Undefine Variable

In summary, you are having difficulty evaluating the parameter "Numerator" in the "HC1/Transfer Fcn" function. The error message you are getting may be because you are using the global variable "c" incorrectly. You should make "c" a global variable so that all the functions that use it can have the same value.
  • #1
50Cent
33
0
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?
 

Attachments

  • Transfer function Error.JPG
    Transfer function Error.JPG
    44.9 KB · Views: 721
Physics news on Phys.org
  • #2
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.
 
  • #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
 

Attachments

  • transfer function.JPG
    transfer function.JPG
    28.4 KB · Views: 712

What is a "Matlab Error: Undefine Variable"?

A "Matlab Error: Undefine Variable" is an error message that indicates that a variable referenced in a Matlab code is not defined or does not exist in the current workspace.

Why am I getting a "Matlab Error: Undefine Variable"?

You may be getting a "Matlab Error: Undefine Variable" because the variable you are trying to use has not been declared or initialized in the code, or it may have been deleted or cleared from the workspace.

How can I fix a "Matlab Error: Undefine Variable"?

To fix a "Matlab Error: Undefine Variable", you can either declare and initialize the variable in the code or make sure it exists in the workspace before using it. You can also use the "exist" function to check if a variable exists in the workspace.

What is the difference between "Matlab Error: Undefine Variable" and "Matlab Error: Undefined Function"?

"Matlab Error: Undefine Variable" and "Matlab Error: Undefined Function" are both error messages that indicate missing or undefined elements in a Matlab code. The main difference is that "Matlab Error: Undefine Variable" refers to a missing variable, while "Matlab Error: Undefined Function" refers to a missing function or command.

How can I prevent "Matlab Error: Undefine Variable" in my code?

To prevent "Matlab Error: Undefine Variable", make sure to declare and initialize all variables in your code before using them. Also, avoid deleting or clearing variables from the workspace if they are needed in the code.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
4K
  • Computing and Technology
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
Replies
40
Views
535
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
5K
Back
Top