xlsread isn't storing all the cell values from a column

조회 수: 5 (최근 30일)
Nivedita Tanksali
Nivedita Tanksali 2021년 5월 5일
댓글: Jeremy Hughes 2021년 5월 6일
I've been using xlsread for a while now, and I've never had Any problems with it.
Recently, however, whenever I try to import values from an excel sheet, each column having more than one cell (19 rows),
for some reason, only a single, unrelated value is stored in the variable created for that column.
Funnily enough, when i tried using readcell for one of the values (p4), I found that p1, p2 and p3 were saved appropriately, as 18 * 1 matrices.
(bottom right corner)
When I reverted back to xlsread for p4, p1,p2, p3 and p4 were again saved as single nonsensical values, although the plot containing p4 had the correct values.
(bottom right corner)
I've never had a problem with xlsread before, so could anyone give me some insight into what is happening?
  댓글 수: 3
Nivedita Tanksali
Nivedita Tanksali 2021년 5월 5일
This is the third sheet from the excel file that I'm trying to import.
The first column (THETA) is being imported as a 18*1 array, but the next four columns aren't being imported similarly.
Jeremy Hughes
Jeremy Hughes 2021년 5월 5일
I'd suggest actual code instead of screenshots of code. It's a lot easier to work with that. Also attaching a real file so people can try the solution would help out.

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

채택된 답변

Star Strider
Star Strider 2021년 5월 5일
Try something like this —
T1 = readtable('YourExcelFile.xlsx', 'Range','A1:E19')
That will import everything as a table, and then refer to the individual variables as —
THETA = T1.Theta;
and so for the rest, although you can simply refer to the individual variables everywhere using their table references.
See the documentations ection on Access Data in Tables for details.
  댓글 수: 6
Nivedita Tanksali
Nivedita Tanksali 2021년 5월 5일
Thank you! I will check it out and you all have been most helpful!
Star Strider
Star Strider 2021년 5월 5일
As always, my pleasure!

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

추가 답변 (2개)

David Fletcher
David Fletcher 2021년 5월 5일
I don't know if this is the problem in your case, but Matlab docs have not recommended the use of xlsread since R2019a. That's not to say it doesn't work in most cases, but there are clearly some known issues with its use
  댓글 수: 2
Nivedita Tanksali
Nivedita Tanksali 2021년 5월 5일
It can't be the problem because I've been using it for half a year so far. No problems until today.
Jeremy Hughes
Jeremy Hughes 2021년 5월 5일
The fifth line is a call to readcell, not xlsread. And the error says, error using readcell.

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


Jeremy Hughes
Jeremy Hughes 2021년 5월 5일
편집: Jeremy Hughes 2021년 5월 5일
The issue is in the call to readcell which isn't using the correct syntax. See readcell documentation for details.
It looks like you've tried to port an xlsread call to readcell withought modifying the inputs to match what readcell expects
[~,~,C] = xlsread(file,sheet,range);
becomes:
C = readcell(file,"Sheet",sheet,"Range",range);
addendum:
You probably want readmatrix actually
A = xlsread(file,sheet,range);
becomes:
A = readmatrix(file,"Sheet",sheet,"Range",range);
  댓글 수: 3
Nivedita Tanksali
Nivedita Tanksali 2021년 5월 5일
So I tried using that, and the following ocurred:
A = readmatrix('ALL_PEAKS_2ND_SET.xlsx',"Sheet",'Poly3 for 10s angles vs time',"Range",'A2:A19');
Sheet name 'Poly3 for 10s angles vs time' does not exist or is
not supported. To check if the sheet is supported, specify the
sheet by its worksheet index.
Jeremy Hughes
Jeremy Hughes 2021년 5월 6일
From the example file, it looks like there is only "Sheet1" and no "Poly3 for 10s angles vs time"
The error message is suggesing "specify the sheet by its worksheet index." meaning use a number instead of the name.

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

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by