Ошибка в матлабе unrecognized function or variable

8,383 views (last 30 days)

MathWorks Support Team

I am receiving one of the following error messages. How can I resolve this issue?

Undefined function or variable ‹Name›.

Unrecognized function or variable ‹Name›.

Undefined function or method ‹Name› for input arguments of type ‹ClassName›.

Accepted Answer

MathWorks Support Team

MATLAB does not recognize the specified string as the name of a function on the MATLAB path or as a variable. The above error messages can be caused by:

1) Trying to use a variable that has not been defined before this line of code executes.

>> x=1:10;

>> t=x.^2;

>> plot(x,y)

Undefined function or variable ‘y’.

2) A typographical error when typing a function or variable name. However, later versions of MATLAB try to resolve these typos with “Did you mean” suggestions. For example,

>> foo = 42;

>> fo0

Undefined function or variable ‘fo0’.

Did you mean:

>> foo

3) The wrong case for a function or variable name. Later versions of MATLAB try to resolve these typos with “Did you mean” suggestions.

4) Changing directories so that a function you used is no longer on the MATLAB path.

5) Trying to use a function for which you are not licensed or that belongs to a MathWorks toolbox that isn’t installed. In later versions of MATLAB, this is not an “Undefined function or variable” error, and MATLAB lets you know that you are either not licensed to use the function or the appropriate toolbox is not installed.

6) Trying to use a function that belongs to a third-party toolbox that isn’t installed.

7) Trying to use a function that does not yet exist in your version of MATLAB.

8) Trying to use a function that has been removed from your version of MATLAB. In later versions of MATLAB, this is not an “Undefined function or variable” error, and MATLAB lets you know the new, preferred function to use.

9) Trying to use a variable that gets cleared from the workspace because your script or function contains «clear all» or «clearvars».

10) Calling an object method without an object as the first input.

11) Using a MEX function that is compiled on a platform different from the one in use.

12) The function or script M-file’s name ends with a capital «.M» extension instead of a lowercase «.m».

Try the following:

1) Verify that the undefined function or variable is visible (it is on the path or in the current workspace) and that it has been defined before this line of code executes. If the undefined identifier is a function, the ‘which‘ function can help you verify that it is visible to the function where the error occurs:https://www.mathworks.com/help/matlab/ref/which.html

2) Verify that the function that you are trying to use is available in your version of MATLAB using the built-in documentation (>> doc). If you cannot find it in our documentation, the function may have been added in a later release of MATLAB, or it may be part of a third-party toolbox that is external to MathWorks.

3) If you are trying to use a function that should be available in your version of MATLAB, from a MathWorks toolbox that you have installed and licensed for, there may be a problem with your MATLAB search path. Run the following MATLAB commands to restore it:

>> restoredefaultpath

>> rehash toolboxcache

>> savepath

See our documentation for more tips:


More Answers (1)

michael

(Matlab R14)

Something strange is that when I try to call some function from toolbox (communication) I’m getting that it is not existing.

Even when I’m going to %MATLABROOT%toolboxcommcomm where the m file is existing, I still can’t run it.

Please suggest what is the issue

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
P=[11500,9500,9000,8500,8000,7500];
V=[100,300,400,500,600, 700];
x=V;
y=P;
Untitled;
P=f;
P1=[800,100,0,-100,-300,-400];
y=P1;
Untitled;
P1=f;
plot(V,P,V1,P1);
 
 
H=[500,1000,2000,3000,4000,5000,6000,7000];
Ro=[1.1673,1.1117,1.0066,0.9093,0.8193,0.7364,0.6601,0.5900];
x=Ro;
y=H;
Untitled;
H=f;
plot(H,Ro);
 
 
Cy=[0,0.25,0.5,0.75,1.0,1.25,1.4];
al=[2,4,7,10,13,17,20];
x=al;
y=Cy;
Untitled;
Cy=f;
plot(al,Cy);
 
 
Cx=[0.02,0.03,0.04,0.05,0.075,0.12,0.17];
al=[2,4,7,10,13,17,20];
x=al;
y=Cx;
Untitled;
Cx=f;
plot(al,Cx);
rihana_jeth asked . 2023-01-13

I am receiving one of the following error messages. How can I resolve this issue?

Undefined function or variable ‹Name›.
Unrecognized function or variable ‹Name›.
Undefined function or method ‹Name› for input arguments of type ‹ClassName›.
undefined , function , variable , error , Language Fundamentals , Entering Commands

Kshitij Singh answered . 2023-06-13 21:56:32

MATLAB does not recognize the specified string as the name of a function on the MATLAB path or as a variable. The above error messages can be caused by:

1) Trying to use a variable that has not been defined before this line of code executes.

>> x=1:10;
>> t=x.^2;
>> plot(x,y)
Undefined function or variable 'y'.
% Possible corrections:
% Change line 3 to "plot(x,t)"
% or Change line 2 from "t=x.^2;" to "y=x.^2;"

2) A typographical error when typing a function or variable name. However, later versions of MATLAB try to resolve these typos with “Did you mean” suggestions. For example,

>> foo = 42;
>> fo0
Undefined function or variable 'fo0'.
Did you mean:
>> foo

3) The wrong case for a function or variable name. Later versions of MATLAB try to resolve these typos with “Did you mean” suggestions.

4) Changing directories so that a function you used is no longer on the MATLAB path.

5) Trying to use a function for which you are not licensed or that belongs to a MathWorks toolbox that isn’t installed. In later versions of MATLAB, this is not an “Undefined function or variable” error, and MATLAB lets you know that you are either not licensed to use the function or the appropriate toolbox is not installed.

6) Trying to use a function that belongs to a third-party toolbox that isn’t installed.

7) Trying to use a function that does not yet exist in your version of MATLAB.

8) Trying to use a function that has been removed from your version of MATLAB. In later versions of MATLAB, this is not an “Undefined function or variable” error, and MATLAB lets you know the new, preferred function to use.

9) Trying to use a variable that gets cleared from the workspace because your script or function contains «clear all» or «clearvars».

10) Calling an object method without an object as the first input.

11) Using a MEX function that is compiled on a platform different from the one in use.

Not satisfied with the answer ?? ASK NOW

I am trying to plot a three dimensional phase portrait of a system of first order differential equations, but I am getting an error message saying I have an unrecognized variable eta. Apart from the three dimensional phase portrait, I also want to plot x(1) versus t, x(2) versus t, and x(3) versus t, all on the same graph. I have commented out this plot command because I’m sure I’m wrong. So, I am looking to plot (i) a 3D phase portrait, and (ii) a time plot of x(1), x(2) and x(3) all on the same graph. Also, the [-0.015,0.015], [-2,2], [-4,4] that you see in the argument of the ode45 are the axes limits of x(1), x(2) and x(3). I am not even sure that the axes limits should be placed there. Could someone please help? Thank you.

[t,x] = ode45(@eqx3, eta, omega, [-0.015,0.015], [-2,2], [-4,4], initcond);
global eta omega
eta = 0.05;
omega = 25;
%tspan = [0,50]
initcond = [1, 0.5, -0.4]


%subplot(211)
%plot(t, x(:,1), t,x(:,2),'--',x(:,3),'--');
%xlabel('t')

subplot(212)
plot(x(:,1), x(:,2), x(:,3))
xlabel('x1')
ylabel('x2')
zlabel('x3')

function xdot = eqx3(t,x,eta,omega)
  global eta omega
  xdot = zeros(3,1);
  xdot(1) = -(2*eta*omega + 1)*x(1) + x(2) - 1;
  xdot(2) = -(2*eta*omega + (omega^2))*x(1) + x(3) + 2;
  xdot(3) = -(omega^2)*x(1) + x(2) - 1;
  %xdot =[xdot(1);xdot(2);xdot(3)];
end

Hi Team

I have this code below and my channel is set to public and now i am getting unrecognized function or variable using ‘avg_temperature’. Anyone who can help me with this issue?

What I have tried:

data = thingSpeakRead(929272, "NumMinutes", 100);
aveTemp = mean(data(:,7));
apiKey = '****';
alertURL = "https://api.thingspeak.com/alerts/send";
options = weboptions("HeaderFields",["ThingSpeak-Alerts-API-Key", apiKey]);
alertBody = sprintf("The temperature is %0.2fF.", aveTemp);
if avg_temperature > 60.0
    webwrite(alertURL, "body", alertBody, "subject", alertSubject, options);
end

Updated 12-Jan-20 22:32pm

Comments


1 solution

Solution 1

Most probably, replace avg_temperature with aveTemp; but it’s just a wild guess.

If this does not solve the issue, then you will have to explain with more details where and how you did define the avg_temperature variable. If you have copied part of this code from somewhere without trying to understand what it does, then you may also have to rethink the way you are learning and experiencing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

 

Print

Answers RSS

Top Experts
Last 24hrs This month

CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900

Понравилась статья? Поделить с друзьями:
  • Ошибка в матлабе index exceeds matrix dimensions
  • Ошибка в майнкрафте консоль разработчика
  • Ошибка в майнкрафте конец потока
  • Ошибка в маткаде значение имеет единицы измерения unitless
  • Ошибка в майнкрафте this server has mods