MATLAB Answers

Error: "Undefined function 'sortrows' for input arguments of type 'double' "

2 views (last 30 days)
Daan Van Cauteren
Daan Van Cauteren on 9 Oct 2020
Commented: Image Analyst on 4 Dec 2020
When running an .m file, I have been running a lot, I suddenly stumbled upon this error. I have never before recieved the error, not even with this code. It occurs in the unique() function. This is the error that shows up in the command window:
Undefined function 'sortrows' for input arguments of type 'double'.
Error in unique>uniqueR2012a (line 322)
sortA = sortrows(a);
Error in unique (line 161)
[varargout{1:nlhs}] = uniqueR2012a(varargin{1},logical(flaginds(1:5)));
The line of code where the error occurs looks like this:
t = 4;
range = repmat([1:3],1,4);
variabelenMatID = nchoosek(range,t);
combinaties = unique(variabelenMatID,'rows');
Scrolling through the fora, I could not find a definitive answer for this problem.
If it helps out, I have run the sortrows() function by itself (see code underneath), but it basically gave the same error.
A = magic(5);
B = sortrows(A);
Also, when using the -which command, the path to the function seems fine...
which sortrows
C:\Program Files\MATLAB\R2018b\toolbox\matlab\datatypes\@categorical\sortrows.m % categorical method
Does anyone know why I suddenly get this error, and how to resolve it?
Kind regards
Ameer Hamza
Ameer Hamza on 9 Oct 2020
I recommend installing MATLAB again. If this file is unknowingly deleted, then there might be other issues too.

Sign in to comment.

Answers (1)

John D'Errico
John D'Errico on 4 Dec 2020
Edited: John D'Errico on 4 Dec 2020
Kind of late, but just so an answer is shown.
If you are missing a function that should be there... As in this case, where the double version of sortrows suddenly seems to have disappeared.
First, verify if the function exists on the search path. In my MATLAB, there are multiple versions of sortrows, several of which I wrote myself. So you can see a VPI version, and one in my VPIJ toolbox. But all of the other sortrows versions all came from MATLAB.
which sortrows -all
/Applications/ % categorical method
/Users/johnderrico1/Desktop/My_FEX/VariablePrecisionIntegersJava/@vpij/sortrows.m % vpij method
/Applications/ % duration method
/Applications/ % datetime method
/Users/johnderrico1/Desktop/My_FEX/VariablePrecisionIntegers/@vpi/sortrows.m % vpi method
/Applications/ % tall method
/Applications/ % timetable method
/Applications/ % tabular method
/Applications/ % dataset method
Most importantly, there should be the basic double precision version of sortrows. This is the default version that MATLAB will lookfor. It SHOULD have been in the datafun directory, provided with MATLAB.
How did I know to look for the double precision version? Re-read the error message. It told you what to look for.
"Undefined function 'sortrows' for input arguments of type 'double'."
Every other version of sortrows is for various alternative classes. The one that has no class associated with it is the one in datafun.
So you should verify several things. If which did not fund sortrows in the datafun directory, then you might look to see if sortrows has been moved from that directory, or if that file was deleted by accident. Note that you should NEVER move files out of the directory that came from as installed by MATLAB, but things happen by accident.
Another possibility is you may have accidentally removed the datafun directory from your search path. This would have been a bad mistake to make, since that directory would have many valuable functions in it. So I would verify that directory does lie on your search path. If not, this is easily repaired, using either addpath or pathtool. Then save your path, and all will now work.
In the worst case, where either the directory itself or the function sortrows has been accidentally deleted, now the simplest way to recover is to re-install a fresh copy of MATLAB. But first, I might spend a little time doing a disk verification step, using whatever utility that is appropriate for your OS. This is because if directories or files have suddenly disappeared from your hard drive, if this is happening because your system is corrupted, that is a major problem. Fix any corruption issues you may find, before you re-install MATLAB. It is not a bad idea to check your system periodically anyway. Then finally, just do a re-install of MATLAB. This is pretty fast to do, especially if you have a fast internet connection. You might as well make sure you have the latest release anyway.
At the very end, if you do a re-install, you will then need to add any of your private directories back onto your new search path.
  1 Comment
Image Analyst
Image Analyst on 4 Dec 2020
Also, calling
>> restoredefaultpath
sometimes fixes such "missing function" problems.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!