Row index exceeds table dimensions.

조회 수: 4 (최근 30일)
olayinka ola
olayinka ola 2020년 11월 16일
댓글: olayinka ola 2020년 11월 19일
In the attached image of my workspace for the below code I can see that adjcls3 is 1663x1 and idx3 is 1889x1 however I don't know how to fix the error I am receiving
"Row index exceeds table dimensions."
Question: How do I solve the row index exeeds table dimensions issue?
Here is the code:
R = readtable("Backtesting/OIH.xlsx");
tday1 = R{1:end, 1};
tday1.Format = 'yyyy-MMM-dd';
adjcls1=R(:,end);
T = readtable("Backtesting/RKH.xls");
tday2 = T{1:end, 1};
tday2.Format = 'yyyy-MMM-dd';
adjcls2=T(:,end);
H = readtable("Backtesting/RTH.xlsx");
tday3 = T{1:end, 1};
tday3.Format = 'yyyy-MMM-dd';
adjcls3=H(:,end);
tday=union(tday1, tday2);
tday=union(tday, tday3);
adjcls=NaN(length(tday), 3);
[foo idx1 idx]=intersect(tday1, tday);
adjcls(idx, 1)=adjcls1{idx1, 1}
[foo idx2 idx]=intersect(tday2, tday);
adjcls(idx, 2)=adjcls2{idx2, 1};
[foo idx3 idx]=intersect(tday3, tday);
adjcls(idx, 3)=adjcls3{idx3, end};
Workspace
  댓글 수: 4
Peter Perkins
Peter Perkins 2020년 11월 19일
Presumably it is the right-hand side that is causing the issue. The problem is not the SIZE of idx3, but the indices that it contains. idx3 contains indices into tday3, while adjcls3 has height equal to tday, which is the union of ...
You are going to need to step though your code and figure out why adjcls3 is the wrong height for the row indices you're using. Likely you are not realizing that union "returns the combined values of the two vectors with no repetitions", and you have repeated days.
olayinka ola
olayinka ola 2020년 11월 19일
Stepping back through the code did it. Simple error from me on line 10:
tday3 = T{1:end, 1};
should have been. Works now
tday3 = H{1:end, 1};

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

답변 (1개)

Athul Prakash
Athul Prakash 2020년 11월 19일
If you could attach the input file, others users may actually run the code with that data and witness the exact error themselves.
However, since you're obtaining the indices from an intersect function (2nd last line), I suspect that somehow it returns more/less values than expected and this is causing your index error. You may inspect the values of 'idx' and 'idx1' by setting a breakpoint on the last line and double-clicking the variables as they appear in the variables section.
Hope it Helps!

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by