# Unrecognized function or variable 'length' ???

74 views (last 30 days)
Kaname Teratsuji on 2 Jul 2020
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.)
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 CommentsShowHide 1 older comment
Kaname Teratsuji on 2 Jul 2020
Somehow MATLAB thinks 'length' is a variable...

madhan ravi on 2 Jul 2020
length(Uu) = len1; % naming a variable length is a terrible idea!!!
clear length
Kaname Teratsuji on 2 Jul 2020
wow what a terrible mistake!!!!
thank you I didnt notice that mistake!