Sudden error "Unidentified function or variable"

조회 수: 3 (최근 30일)
Kyle Dalminton
Kyle Dalminton 2021년 7월 26일
댓글: DGM 2021년 7월 26일
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
DGM 2021년 7월 26일
편집: DGM 2021년 7월 26일
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
Kyle Dalminton
Kyle Dalminton 2021년 7월 26일
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 2021년 7월 26일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Chunru
Chunru 2021년 7월 26일
[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
Kyle Dalminton
Kyle Dalminton 2021년 7월 26일
Thank you for your effort. I see the problem now

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by