Hi
I have a 143x4 matrix, which looks like this
A=[ 1 556037.025 6237642.046 5.964;
1 556037.035 6237642.041 5.960;
1 556037.028 623742.041 5.967;
2 556032.654 623730.067 10.368;
2 556032.652 623730.060 10. 364;
4 556042.000 623730.000 5.000;
4 556042.002 623730.005 5.010] ;
Column 1 is the point number, column 2-4 are X,Y,Z coordinates.
Each point is measured between 1 and 5 times.
My code is:
A=load('Test.txt');
A=sortrows(A);
T=array2table(A);
m=varfun(@mean,T,'GroupingVariables',1);
out=A;
out(:,2:end)=out(:,2:end) - m{A(:,1),3:end}
I get the error Row index exceeds table dimensions
I have tried to test different scenarios and the error occurs when a point is missing, for example if there is no point number 7, so the first column goes from 6 to 8.
Any idea what is wrong?

댓글 수: 4

KSSV
KSSV 2019년 4월 24일
Which line is givng you the error? I think what you have shown is not a complete code.
Peter Larsen
Peter Larsen 2019년 4월 24일
The error is caused by this line:
out(:,2:end)=out(:,2:end) - m{A(:,1),3:end}
Peter Larsen
Peter Larsen 2019년 4월 24일
The complete code is updated now
Peter Larsen
Peter Larsen 2019년 4월 24일
Hi
It works until the numbers in column 1 skips a number (See updated revision). If the point number skips from 2 to 4 without having a point number 3, the error occurs

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

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2019년 4월 24일

1 개 추천

T = array2table(A);
m = varfun(@mean,T,'GroupingVariables',1);
out = A;
[~,~,ii] = unique(A(:,1));
out(:,2:end) = out(:,2:end) - m{ii,3:end};

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2018b

질문:

2019년 4월 24일

댓글:

2019년 4월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by