indexing error for loop: "In an assignment A(I) = B, the number of elements in B and I must be the same."

조회 수: 1 (최근 30일)
Good Afternoon,
I am having a bit of trouble with my for loop. I have two data sets of A and B with a different number of rows but same number of columns. I would like the dimension size to match by taking the remaining points left in the larger matrix and finding the closest points (smallest distance) of that in the other set. This is done by the knnsearch function in matlab. Currently I am getting the error of "In an assignment A(I) = B, the number of elements in B and I must be the same." but when I remove the i from New_Bi the loop over writes itself... Any suggestions?!?
Thanks in advance.
[ma,na]=size(A); [mb,nb]=size(B);
range=[mb+1:ma];
od=knnsearch(B,A);
index=od(range);
for i=1:length(index)
New_Bi(i)=A(index(i),:);
end
New_B=[B; New_Bi]
New_A=A;

채택된 답변

Iain
Iain 2013년 8월 20일
The issue is that you're trying to put a matrix into the space that a scalar would take. Try:
New_Bi(i,:) = A(index(i),:);

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by