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!

 채택된 답변

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

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!

댓글을 달려면 로그인하십시오.

추가 답변 (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