Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: data extraction from matrix to use in another matrix
Replies: 26   Last Post: Oct 22, 2013 4:57 PM

 Messages: [ Previous | Next ]
 dpb Posts: 9,850 Registered: 6/7/07
Re: data extraction from matrix to use in another matrix
Posted: Oct 22, 2013 12:59 PM

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.

Each M entry i is simply

[conn(i,:) node(conn(i,2),2:end) node(conn(i,3),2:end)]

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"

>> for i=1:length(conn)
M(i,:)=[conn(i,:) Node(conn(i,2),2:end) Node(conn(i,3),2:end)];
end
>> M
M =
1 5 2 1 1 2 0
2 2 3 2 0 4 0
3 3 4 4 0 6 0
4 4 7 6 0 5 1
5 3 7 4 0 5 1
6 3 6 4 0 3 1
7 6 2 3 1 2 0
8 5 2 1 1 2 0
9 1 5 0 0 1 1
10 5 6 1 1 3 1
11 6 7 3 1 5 1
>>
--

Date Subject Author
10/19/13 walter Mulvany
10/19/13 dpb
10/19/13 walter Mulvany
10/19/13 dpb
10/19/13 walter Mulvany
10/20/13 dpb
10/20/13 walter Mulvany
10/20/13 dpb
10/20/13 walter Mulvany
10/21/13 walter Mulvany
10/21/13 dpb
10/21/13 dpb
10/21/13 walter Mulvany
10/21/13 dpb
10/21/13 walter Mulvany
10/22/13 walter Mulvany
10/22/13 dpb
10/22/13 walter Mulvany
10/22/13 walter Mulvany
10/22/13 dpb
10/22/13 walter Mulvany
10/22/13 dpb
10/22/13 dpb
10/22/13 walter Mulvany
10/22/13 dpb
10/22/13 dpb
10/20/13 dpb