Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think this can be done using some string evaluation and <a href="http://www.mathworks.com/help/techdoc/ref/f16-42340.html#f16-7121" rel="nofollow">set operations</a>.</p> <p>If we have</p> <pre><code>result = me: {'dad' 'grandpa' 'half_sis'} step_mom: {'half_sis'} dad: {'me' 'grandpa' 'half_sis'} half_sis: {'mom' 'me' 'dad' 'grandpa'} grandpa: {'me' 'dad' 'half_sis'} </code></pre> <p>We can select one person and find that persons relatives. </p> <pre><code>s = result.step_mom s = 'half_sis' </code></pre> <p>Using some string operations we can then find the relatives of the relatives like this:</p> <pre><code>eval(char(strcat('result.',s))) ans = 'mom' 'me' 'dad' 'grandpa' </code></pre> <p>This gives us an idea for a function:</p> <pre><code>function children=recur_getchildren(result,person) %Find all relatives of given person s = eval(strcat('result.',person)); %Go through all relatives found in s for i=1:size(s,2) children = union(s(i),eval(char(strcat('result.',s(i))))); end %remove orignal relative from other relatives children=setdiff(children,person); </code></pre> <p>Lets test it:</p> <pre><code>relatives=recur_getchildren(result,'mom') relatives = 'dad' 'grandpa' 'half_sis' 'me' </code></pre> <p>Note that you need to change step_mom into mom (or vice versa) for this to work in all cases.</p> <p>EDIT: Just make it recursive. Something like this:</p> <pre><code>function [All_relatives,not_examined]=... recur_getchildren(result,person,examined,All_relatives) %Find all relatives of given person s = eval(strcat('result.',person)); children = ''; %Go through all relatives found in s for i=1:size(s,2) children = union(children,eval(char(strcat('result.',s(i))))); end %Save all found relatives All_relatives = union(All_relatives,children); All_relatives = union(All_relatives,s); %Save all examined persons examined = union(examined,s); examined = union(examined,person); not_examined = setdiff(All_relatives,examined); count=0; while length(not_examined)&gt;0 count=count+1; examined = union(examined,not_examined(count )); [new_relatives,not_examined] = recur_getchildren(result,char(not_examined(count)),examined,All_relatives); All_relatives = union(All_relatives,new_relatives); end </code></pre> <p>This was just quickly put together, but should work. Give <em>examined</em> and *All_relatives* input as empty strings when running. </p> <pre><code>children=recur_getchildren(result,'me','','') </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload