Thread Subject: nested structure

Subject: nested structure

From: Abdul Rauf Anwar

Date: 21 Nov, 2009 18:48:02

Message: 1 of 3

hi everyone
i am having problem regarding find a specific value inside nested structure. problem is regarding tree formation in which one node can take another node as its child.
and task is to traverse to final leaf.
i have got my structure correct and after execution. if i type this on prompt

>> node(11).right.right.left

ans =

     6

>> node(11).right.right

ans =

      left: 6
     right: [1x1 struct]
      freq: 0.3182
    isLeaf: 'false'

is there someway that i get complete path for only doubles ( which is 6 in above example ) as node(11).right.right.left
and it should not give path for 'non doubles' ( which is [1x1 struct] )
thanks in anticipation

Subject: nested structure

From: Matt

Date: 21 Nov, 2009 22:04:06

Message: 2 of 3

"Abdul Rauf Anwar" <raufanwar@gmail.com> wrote in message <he9cl2$rcn$1@fred.mathworks.com>...
> hi everyone
> i am having problem regarding find a specific value inside nested structure. problem is regarding tree formation in which one node can take another node as its child.
> and task is to traverse to final leaf.
> i have got my structure correct and after execution. if i type this on prompt
>
> >> node(11).right.right.left
>
> ans =
>
> 6
>
> >> node(11).right.right
>
> ans =
>
> left: 6
> right: [1x1 struct]
> freq: 0.3182
> isLeaf: 'false'
>
> is there someway that i get complete path for only doubles ( which is 6 in above example ) as node(11).right.right.left
> and it should not give path for 'non doubles' ( which is [1x1 struct] )
> thanks in anticipation

You need to write a function that loops through the fields of the struct and checks which ones are doubles, e.g.


isdouble=isa(node.left, 'double');

You must call this function recursively in order to descend through the tree and have this applied at all levels.

Subject: nested structure

From: Abdul Rauf Anwar

Date: 27 Nov, 2009 02:19:03

Message: 3 of 3

Thanks Matt for your reply , i have moved a bit forward and now stuck with this thing
Root is a structure as given below at start

Root =

      left: [1x1 struct]
     right: [1x1 struct]
      freq: 20
    isLeaf: 0
      code: []
    symbol: []

and at one of leaves ( extreme right ) it looks like this
>> Root.left.right.left.right

ans =

      left: []
     right: []
      freq: 1
    isLeaf: 1
      code: [0 1 0 1]
    symbol: 23


I have written the following code to traverse this tree to symbol '23' but it isnt working :(


function [ code1 ] = testing1(node)
while (Root.isLeaf==true)
if (node.symbol == '23')
    code1=node.code;
    return;
   else
    code1=testing1(node.left);
end
if (node.symbol=='23')
    code1=node.code;
    return;
 else
     code1=testing1(node.right);
end
end
return;

Thanks in Anticipation

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
nested structure Abdul Rauf Anwar 21 Nov, 2009 13:49:03
rssFeed for this Thread

Contact us at files@mathworks.com