Sudden error "Unidentified function or variable"

3 vues (au cours des 30 derniers jours)
Kyle Dalminton
Kyle Dalminton le 26 Juil 2021
Commenté : DGM le 26 Juil 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

Réponse acceptée

DGM
DGM le 26 Juil 2021
Modifié(e) : DGM le 26 Juil 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 commentaires
Kyle Dalminton
Kyle Dalminton le 26 Juil 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 le 26 Juil 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.

Connectez-vous pour commenter.

Plus de réponses (1)

Chunru
Chunru le 26 Juil 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
  1 commentaire
Kyle Dalminton
Kyle Dalminton le 26 Juil 2021
Thank you for your effort. I see the problem now

Connectez-vous pour commenter.

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by