readcell command doesn't work anymore!

조회 수: 11 (최근 30일)
Lara QASIM
Lara QASIM 2020년 3월 23일
편집: Stephen23 2022년 6월 8일
Hi all,
I have a matlab code that reads data from an excel sheet using the readcell function.
I have a data starting in cell B3 to Bx (x can be different).
So I used the following finction to get these data
x1 = readcell("model","sheet","sheet name","Range",'B3:B3');
This function used to give me the needed results (all non empty cells in col B starting from B3). However, I just tried to run my code again today and I was chocked that this command doesn't work anymore!!! error !!!
any idea? please help me!
Thanks in advance,
Lara
  댓글 수: 4
Lara QASIM
Lara QASIM 2020년 3월 23일
This is the error:
and the error message i got is :
Index in position 1 exceeds array bounds (must not exceed 1).
Error in orient (line 35)
FCM_f(j).Function=char(x1(j,1));
This is part of the code where the error occurs:
Size_FCM = size(FCM);
x1 = readcell("model","sheet","Global FCM","Range",'B3:B3');
for j= 1:Size_FCM(1,1)
FCM_f(j).value=FCM(j,:);
FCM_f(j).Function=char(x1(j,1));
end
Lara QASIM
Lara QASIM 2020년 3월 23일
When I checked x1 .. itonly has the value from cell B3 and not all the col.
That's when when j=2 I have an error..
but the question is why this function used to work and just suddenly stopped working?

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

채택된 답변

Stephen23
Stephen23 2020년 3월 23일
편집: Stephen23 2020년 3월 23일
This only reads one cell:
"Range",'B3:B3'
There is nothing in your code that reads "all non empty cells in col B starting from B3" as you write. It just reads B3.
  댓글 수: 6
NAFTALI HERSCOVICI
NAFTALI HERSCOVICI 2022년 6월 8일
is there a way to use cell numbers to specify a a range?
Like [2 3] instead of 'B3'.
I tried x1 = readcell("model","sheet","Global FCM","Range",[2 3]); and got the error "Unable to determine range".
Is this a syntax problem or simply cannot be done?
Stephen23
Stephen23 2022년 6월 8일
편집: Stephen23 2022년 6월 8일
"is there a way to use cell numbers to specify a a range?"
Yes, according to the documentation the current READCELL permits a 2-element (start cell) and 4-element (start and end cells) numeric vectors for the RANGE option:
"Is this a syntax problem or simply cannot be done?"
It can be done. Lets try it here (sample file is attached, with UsedRange from A1 to C3):
C = readcell('test.xlsx','Range',[2,2])
C = 2×2 cell array
{[22]} {[23]} {[32]} {[33]}
That gives exactly the expected output without error.
The error message you showed sounds like there is some ambiguity with your worksheet. But if you do not upload a sample workbook by clicking the paperclip button then I cannot debug this for you.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by