Relating matrices through the use of indices (Matlab 2011)

1 次查看(过去 30 天)
I'm writing a program that, given a set of input coordinate points and segments (nx2 and nx3 matrices respectively) graphs the cross-section including thickness of each segment.
I've got two matrices defined by user input. The first is the nx2 matrix (each row represents a set of coordinate points, x and y) and the second is the nx3 matrix where the limit of 'n' goes to infinity. For example:
A=[0 0; 10 0; 0 10; 10 10; 5 0; 5 10]
B=[1 2 0.5; 3 4 0.5; 5 6 0.25]
I'm attempting to construct a bit of code that relates B to A such that the first two terms of each row of B indicates the index of each term in A. The third term assigns a value to the thickness of the segment between the two. Therefore in B, 1 2 indicates the first and second terms of A (being 0 0 and 10 0).
I've attempted this using this method thus far:
[x index]=A(:,1)
but this simply yields the error "??? Indexing cannot yield multiple results."

回答(1 个)

Jos (10584)
Jos (10584) 2014-3-13
Does this help you?
A = [0 0 ; 10 0 ; 0 10; 10 10; 5 0; 5 10]
B = [1 2 0.5; 3 4 0.5; 5 6 0.25]
x1 = A(B(:,1),:)
x2 = A(B(:,2),:)
x3 = B(:,3)
x = [x1 x2 x3]

类别

Help CenterFile Exchange 中查找有关 Software Development Tools 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by