Why Matlab doesn't see part of the excel sheet?

3 views (last 30 days)
CheshireM
CheshireM on 28 Oct 2021
Answered: Image Analyst on 28 Oct 2021
I read multiple sheets excel file with following code:
Sheets = sheetnames(FileName);
for i = 1 : length(Sheets)
Name = Sheets{i};
data{i} = readmatrix(FileName,'Sheet',Name);
end
Each sheet looks the same: A1 cell is "Student ID" and A2 is "#" (ID number).
B1 is "Math grades", B2, B3, etc - grades (just numbers).
When I look at data cell array I see that some cells have this first row with ID, and some don't.
Any idea why is that?
Thank you!!

Answers (1)

Image Analyst
Image Analyst on 28 Oct 2021
"data" is a cell array because you used braces, not because that's what readmatrix() returns. Actually readmatrix() returns a numerical matrix - a double - which has no strings at all in it. And it's putting that numerical/double matrix into the ith cell of data.
If you want a cell array, so that it will have both numbers and strings, instead of a matrix, then use readcell() instead of readmatrix().
Please read the FAQ on cell arrays and you will understand better.

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!