Sudden error "Unidentified function or variable"

3 Ansichten (letzte 30 Tage)
Kyle Dalminton
Kyle Dalminton am 26 Jul. 2021
Kommentiert: DGM am 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

Akzeptierte Antwort

DGM
DGM am 26 Jul. 2021
Bearbeitet: DGM am 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 Kommentare
Kyle Dalminton
Kyle Dalminton am 26 Jul. 2021
Ah I see, thank you for pointing this out. I was panic since it worked perfectly last night. It makes me wonder why X1 suddenly disappeared? Anyway, thank you and have a good day.
DGM
DGM am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Chunru
Chunru am 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

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by