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 Center および File ExchangeEnvironment and Settings についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by