xlsread error: Array indices must be positive integers or logical values.

When I try to use xlsread to read the attached Excel file:
[A B C] = xlsread('AA.xlsx');
Why do I keep getting this error? It seems the problem is the last column, but why?
Error using xlsread (line 257)
Array indices must be positive integers or logical values.
Many thanks!

 Réponse acceptée

I was able to read your file without error.
However, if you have R2013b or lalter release, the readtable (link) function is likely the best option for your file:
AA_Table = readtable('AA.xlsx')

5 commentaires

Leon
Leon le 4 Juin 2019
Modifié(e) : Leon le 4 Juin 2019
Thanks for the suggestion of using readtable.
If I use [A B C] = xlsread('AA.xlsx'), my header info will be stored in B(1,:). Where will my header info stored, if I use T = readtable('AA.xlsx')?
I need to use the below command to query the headers to find the columns that I'm interested in:
isMatch = contains(B(1,:), 'abc', 'IgnoreCase',true)
Definitively use readtable if your table has header. The header is converted into a variable name and not part of the data. If the rest of the data is numeric it is a lot more practical. To get the data matching the 'abc' header:
t = readtable(yourexcelfile);
t.abc
So much simpler!
Read the doc about tables.
Try this:
AA_Table = readtable('AA.xlsx');
headers = AA_Table.Properties.VariableNames;
isMatch = contains(headers, 'abc', 'IgnoreCase',true);
When I tested that although using 'ph' as the match string, this worked correctly.
I am using Excel 2016 in Windows 10. I have no idea how Excel is implemented on a Mac.
Many thanks! It works.
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (1)

Leon
Leon le 4 Juin 2019
Thanks all for the replies. I'm using Excel Version 16.25 on MacOS 10.14.5

Catégories

Produits

Version

R2019a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by