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!

 採用された回答

Star Strider
Star Strider 2019 年 6 月 4 日
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 件のコメント

Leon
Leon 2019 年 6 月 4 日
編集済み: Leon 2019 年 6 月 4 日
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)
Guillaume
Guillaume 2019 年 6 月 4 日
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.
Star Strider
Star Strider 2019 年 6 月 4 日
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.
Leon
Leon 2019 年 6 月 4 日
Many thanks! It works.
Star Strider
Star Strider 2019 年 6 月 4 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (1 件)

Leon
Leon 2019 年 6 月 4 日

0 投票

Thanks all for the replies. I'm using Excel Version 16.25 on MacOS 10.14.5

製品

リリース

R2019a

タグ

質問済み:

2019 年 6 月 4 日

コメント済み:

2019 年 6 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by