Why am I getting unrecognized function or variable 'length' ??
18 views (last 30 days)
Ana Gabriela Guedes on 6 Nov 2022
Hi!! I am building a code to create a convolutional neural network but for some reason when I call the function used to train the CNN it always raises an error "Unrecognized function or variable 'length'" at the same point.
I don't understand why this happens since "length" in an intrinsic matlab function and its working well on other functions/scripts...
%Building 4D matrix (29 (instants)x29 (features) x1 (because images are grey) x numberofImages)
newPtrain=; newTrg_train=; window_width=29; count=0;
% THIS IS WHERE THE ERROR RAISES
% REST OF THE CODE
Walter Roberson on 7 Nov 2022
At some point in the same function, you assigned a value to a variable named length . Once you do that, then even if you clear it again, you can no longer use length as a function within the same function.
If you have a variable and call a function with the same name inside a function, then the first version that MATLAB encounters during executing the function "locks in" MATLAB's interpretation of what the name is to be. If you had called the function length() before assigning to a variable named length then when you tried to use length as a variable MATLAB would have complained that it could not find the variable. If you had assigned to a variable named length before you called length as a function, then even if you had cleared the variable, then inside the function you would no longer be able to call the function length. You cannot use the same name as both a variable and a function within the same function.