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

조회 수: 1 (최근 30일)
CheshireM
CheshireM 2021년 10월 28일
답변: Image Analyst 2021년 10월 28일
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!!

답변 (1개)

Image Analyst
Image Analyst 2021년 10월 28일
"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.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by