Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

Re: Problem using horzcat with index vectors in a for loop

$
0
0
Yes, apologies again for my lack of clarity.
Original data:

originalA =
     2 4 3.1 2.5
     5 7 3.4 3.7
     2 4 6.7 2.8
     3 1 3.3 7.6
     8 4 4.6 6.7

originalB =
     5 7 5.8 9.5
     2 4 5.1 4.5
     2 2 4.2 3.5
     8 4 5.5 3.8
     3 1 4.2 1.3

%Segment

A = originalA(1:2,:)
B = originalB1:2,:)
vectors = originalA(3:4,:)
vectors2 = originalB(3:4,:)

A =
     2 4
     5 7
     2 8
     3 1
     8 4
B =
     5 7
     2 4
     2 2
     8 4
     3 1

vectors =
3.1 2.5
3.4 3.7
6.7 2.8
3.3 7.6
4.6 6.7

vectors2 =
5.8 9.5
5.1 4.5
4.2 3.5
5.5 3.8
4.2 1.3

%find intersections in A and B

C = %matched rows

     2 4
     3 1
     5 7
     8 4
ia = % A row indices

     1
     4
     2
     5

ib = %B row indices

     2
     5
     1
     4

[C,ia,ib] = intersect(A,B,'rows', 'legacy'); % find matched rows

% Match non matching data using the indices found in the previous step

vmatch = zeros(4,4);
for i=1:length(C)
    vmatch(i,:) = horzcat(vectors(ia(i),:), vectors2(ib(i),:))';
end

This is the the problem I was trying to solve. Sorry for the confusion!
Thomas

Viewing all articles
Browse latest Browse all 19628

Trending Articles