dpb
Posts:
9,804
Registered:
6/7/07


Re: data extraction from matrix to use in another matrix
Posted:
Oct 19, 2013 1:22 PM


On 10/19/2013 11:03 AM, walter Mulvany wrote: > I'm writing a code for finite element analysis and I don't know how to > read a value from a matrix (A) and use it as a pointer to direct me to > values in another matrix. > Here is a sample of the problem. ...
> connectivity=[1,1,2;2,1,3;3,2,3] ... > coordinates=[1,0,0;2,2,0;3,1,2] ... > I need to read element's 1 node(a) which in this case is 1, and use that > 1 to direct me to the node 1, extract the x and y coordinate from node > 1, and create a matrix. ...
Well, it's not clear which you're after, but it's simple enough to find a location in an array by value and get the associated information from some other for that.
If ask for points in connectivity array that include node 1, that's given by
>> conn=[1,1,2;2,1,3;3,2,3]; >> coord=[1,0,0;2,2,0;3,1,2]; >> idx=any(conn==1,2) % row indices of any connections w/ a '1' idx = 1 1 0 >> coord(idx,:) % get those rows' coordinates... ans = 1 0 0 2 2 0 >> coord(any(conn==1,2),:) % do it w/o the intermediate variable ans = 1 0 0 2 2 0 >>
Look in subject index for "logical addressing" ...


