readmatrix not working in 2021b

I upgraded to MATLAB 2021b and readmatrix no longer works. In every case I have tried* I get the error
"Error using readmatrix (line 158)
Dimensions of arrays being concatenated are not consistent."
For example, when I follow the example in the documentation and create a basic_matrix text file with the same input as listed in the documentation and verify its contents as demonstrated in the documentation (as shown below), I get the following
>> type basic_matrix.txt
6,8,3,1
5,4,7,3
1,6,7,10
4,2,8,2
2,7,5,9
>> M = readmatrix('basic_matrix.txt')
Error using readmatrix (line 158)
Dimensions of arrays being concatenated are not consistent.
I have quite a bit of code which I previously used to read data from text files and I can no longer open this data in MATLAB.
I am running on an Intel 2020 MacBook Pro.
==========
*The one exception in which I can get readmatrix to work is a horizontal csv entries as shown below. I tried all combinations I could think of using csv extensions, space between entries, etc.
>> type test.txt
1,2
>> M = readmatrix('test.txt')
M =
1 2

4 Comments

Unfortunately you've delayed a response by forgetting to attach your data file.
You are referring to the text file I copied the contents of? Here it is
Experiment with
restoredefaultpath; rehash toolboxcache
I suspect that you have a third-party function that is interfering with one of the built-in functions
Thanks, Walter. I tried this but it did not work unfortunately.
>> restoredefaultpath
>> rehash toolboxcache
>> M = readmatrix('basic_matrix.txt')
Error using readmatrix (line 158)
Dimensions of arrays being concatenated are not consistent.

Sign in to comment.

 Accepted Answer

Jeremy Hughes
Jeremy Hughes on 1 Nov 2021
I agree with the previous answer, but readmatrix is probably not what's being shadowed. It's probably something readmatrix relies on.
You can use the following to find the exact place where an error comes from:
>> dbstop if caught error.
But you may need to continue multiple times as readmatrix may encounter internal errors as part of normal functioning. So when you find the error you're looking for, check all the variable names and function on that line (and then in that function) to see if there's something showing up with "which -all <each-thing-on-that-line>".
You can also try removing anything from PATH that isn't part of the MATLAB installation. If this kind of issue persists between installs, it's probably something in a third-party install, or your personal MATLAB folder.

4 Comments

After corresponding with Wenbo from customer support today (maybe you were also there behind the scenes!) we did this and found the following error
Caught-error breakpoint was hit in detectMetaRows>getMaxMetaRows at line 58. The error was:
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
58 metaRowsMax = min([metaRowsMax,find(~text(:,jj),1)-1]);
I tried which -all on everything on that line, but no cigar. I wasn't sure what to do next, but this turned out to be a clue to the MATLAB team to take a look at height with which -all height, and I discovered that I had a height function in a height.m file in my MATLAB directory. Apparently this height function is necessary for calculation of metaRowsMax. Renaming that m file/function allowed readmatrix to work properly. I'm surprised that this cropped up as an issue now, 4 years after I created that m file, but glad this is now resolved. Thanks for the help!
I believe height used to only work with tables, and has been extended to work with other arrays, along with width. This is probably why it's failing now.
The height and width functions for arrays were introduced in release R2020b as stated in the Release Notes.
Can't you simply choose a new name for your height function? That's probably the easiest fix. Do control-shift-F at some top level folder and search all m-files for "height(". Any you calls to height() you see that are yours, change them to the new name you've picked for it.

Sign in to comment.

More Answers (0)

Products

Release

R2021b

Community Treasure Hunt

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

Start Hunting!