Unrecognized function or variable 'length' ???

조회 수: 5 (최근 30일)
Kaname Teratsuji
Kaname Teratsuji 2020년 7월 2일
댓글: Kaname Teratsuji 2020년 7월 2일
Hello, I'm working on a program, in which I need to measure the length of arrays;
But whenever I use length(var), it prompts 'unrecognized function or variable 'length'' (Line 3).
I thought length() was a built-in variable...
By the way, typing in length(1:20) in the command line works (outputs 20.)
How come it does not work in my codes?? Someone please help!
function w = KUFSolve(K,u,f)
U = [(1:length(u))' u];
F = [(1:length(f))' f];
Uk = [];
F1 = [];
Uu = [];
F2 = [];
for i = 1 : length(U)
if ~isnan(U(i,2))
Uk(size(Uk,1)+1,:) = [U(i,1) U(i,2)];
F1(size(F1,1)+1,:) = [F(i,1) 0];
else
Uu(size(Uu,1)+1,:) = [U(i,1) 0];
F2(size(F2,1)+1,:) = [F(i,1) F(i,2)];
end
end
Unew = cat(1,Uk,Uu);
Fnew = cat(1,F1,F2);
length(Uu) = len1;
length(Unew) = len2;
T = eye(length(U));
Tnew = zeros(length(U));
for i = 1 : length(U)
Tnew(i,:) = T(Unew(i,1),:);
end
T = Tnew;
Kt = T * K * T';
ut = Unew(:,2);
ft = Fnew(:,2);
K11 = Kt(1:len1, 1:len1);
K12 = Kt(1:len1, len1+1:len2);
K21 = Kt(len1+1:len2, 1:len1);
K22 = Kt(len1+1:len2, len1+1:len2);
uk = ut(1:len1);
fk = ft(len1+1:len2);
uu = K22\( fk - K21*uk ); %剛性方程式
fu = K11*uk +K12*uu;
u = T' * [uk; uu];
f = T' * [fu; fk];
R = {u,f};
w = R;
  댓글 수: 2
Kaname Teratsuji
Kaname Teratsuji 2020년 7월 2일
by the way, variable 'u' is a 324x1 array of numbers.
Kaname Teratsuji
Kaname Teratsuji 2020년 7월 2일
Somehow MATLAB thinks 'length' is a variable...

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

채택된 답변

madhan ravi
madhan ravi 2020년 7월 2일
length(Uu) = len1; % naming a variable length is a terrible idea!!!
clear length
  댓글 수: 1
Kaname Teratsuji
Kaname Teratsuji 2020년 7월 2일
wow what a terrible mistake!!!!
thank you I didnt notice that mistake!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by