On 10/22/2013 9:54 AM, walter Mulvany wrote: > What I need to do is to go to element 1, read the value of (conn - > column 2) which is 5, go to the coord matrix, find the value (5) in its > column 1 and extract the x value that correspond to that location (5) > from (coord - column 2) which in this case is (1). > > In other words, I have to connect the 2 matrices (conn and coord), and > the result matrix have to contain conn plus the respective x , y values > of each node a and b > ...
> Elem From To ax ay bx by > 1 5 2 1 1 2 0 > 2 2 3 2 0 4 0 > 3 3 4 4 0 6 0 > > I hope this is clear. Thanks.
OK, now you've gotten a self-consistent description.
And as noted above, you don't need to do any lookup -- assuming the node array is sequential and none missing it's simply an indirect reference.
If you were to have missing nodes, simply add the additional level of indirection previously illustrated with conn(i,2|3) being find(node(:,1)==conn(i,2|3)) for the row index.
Again, NB that while the above keeps your use of the sequential column vector in the first column of the two arrays, there's no reason at all to store it unless you're going to allow the user to not specify all.
And, as previously mentioned, the above can be done w/o looping via accumarray() -- I'll leave that as "exercise for the student"