# Sudden error "Unidentified function or variable"

1 view (last 30 days)
Kyle Dalminton on 26 Jul 2021
Commented: DGM on 26 Jul 2021
Hello everyone
I've got a problem when trying to run a code today. While the code ran perfectly yesterday, it only showed "Unidentified function or variable" today. Can anybody help me with this? Thank you very much.
My code:
[X1 Y1] = Elispe(1, sqrt(4/3), 0, 0, 0, 2*pi);
Z1 = zeros(1, length(X));
Z2 = ones(1, length(X));
X = [X1;X1];
Y = [Y1;Y1];
Z = [Z1;Z2];
%figure
Purple = [0.5,0,1]
surface(X,Y,Z, 'EdgeColor',Purple);
function [X Y] = Elispe(r1,r2, h, k, a, b)
t = linspace(a, b, 50);
X = r1*cos(t) + h;
Y = r2*sin(t) + k;
end

DGM on 26 Jul 2021
Edited: DGM on 26 Jul 2021
Did you read what the error message said?
Unrecognized function or variable 'X'.
Error in untitled (line 3)
Z1 = zeros(1, length(X));
So what is X? Is it X1?
Z1 = zeros(1, length(X1));
Z2 = ones(1, length(X1));
I imagine the only reason this once worked was because there was a volatile copy of X just floating around in the workspace -- probably left over from when you changed variable names or something.
##### 2 CommentsShowHide 1 older comment
DGM on 26 Jul 2021
It happens. When building stuff in a sandbox, it's helpful to run clearvars at least every now and then to make sure your code isn't relying on ephemeral variables that aren't being set by the current version of the code. If things are going to break, it's best they break while you still have your eyes and mind on it.

Chunru on 26 Jul 2021
[X1 Y1] = Elispe(1, sqrt(4/3), 0, 0, 0, 2*pi);
% Z1 = zeros(1, length(X));
Z1 = zeros(1, length(X1));
%Z2 = ones(1, length(X));
Z2 = ones(1, length(X1));
X = [X1;X1];
Y = [Y1;Y1];
Z = [Z1;Z2];
%figure
Purple = [0.5,0,1]
Purple = 1×3
0.5000 0 1.0000
surface(X,Y,Z, 'EdgeColor',Purple); function [X Y] = Elispe(r1,r2, h, k, a, b)
t = linspace(a, b, 50);
X = r1*cos(t) + h;
Y = r2*sin(t) + k;
end
Kyle Dalminton on 26 Jul 2021
Thank you for your effort. I see the problem now

R2019a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!