Skip to main content
1-Visitor
May 28, 2012
Solved

How to analyze nested objects?

  • May 28, 2012
  • 1 reply
  • 2629 views

OK, so I need to check whether the object is acceptable for further actions which means:

elements.jpg

Object is a matrix, all I care is that it has more than 1 row and more than 1 column (type 1).

Object is a vector (more than 1 row), its elements are type 1 objects of the same size (type 2).

Object is a vector, its elements are type 2 objects not only of the same size, but also all the type 1 objects within are of the same size (type 3).

In the same fashion we can define type 4, type 5 and so on indefinitely.

I hope you get the idea.

I'm pretty bad at recursion, but I tried, see project.xmcd .

EDIT: Corrected a mistype in the attached file. Still far from working I guess.

Best answer by StuartBruff

Pranas Pranas wrote:

OK, so I need to check whether the object is acceptable for further actions which means:

Object is a matrix, all I care is that it has more than 1 row and more than 1 column (type 1).

Object is a vector (more than 1 row), its elements are type 1 objects of the same size (type 2).

Object is a vector, its elements are type 2 objects not only of the same size, but also all the type 1 objects within are of the same size (type 3).

In the same fashion we can define type 4, type 5 and so on indefinitely.

I hope you get the idea.

I'm pretty bad at recursion, but I tried, see project.xmcd .

EDIT: Corrected a mistype in the attached file. Still far from working I guess.

I'm not I've understood you correctly, but do you want a 'path' (signature) that indicates the total nesting for each nested element (ie, you could have, in Case 3, a top level object with 3 matrices at the lowest level in the first nested element and another with only 2 matrices) which will allow you to say the 'skeleton' or 'framework' of each nested array is the same?

Is the attached anywhere in the right ballpark?

Stuart

1 reply

23-Emerald V
May 28, 2012

Pranas Pranas wrote:

OK, so I need to check whether the object is acceptable for further actions which means:

Object is a matrix, all I care is that it has more than 1 row and more than 1 column (type 1).

Object is a vector (more than 1 row), its elements are type 1 objects of the same size (type 2).

Object is a vector, its elements are type 2 objects not only of the same size, but also all the type 1 objects within are of the same size (type 3).

In the same fashion we can define type 4, type 5 and so on indefinitely.

I hope you get the idea.

I'm pretty bad at recursion, but I tried, see project.xmcd .

EDIT: Corrected a mistype in the attached file. Still far from working I guess.

I'm not I've understood you correctly, but do you want a 'path' (signature) that indicates the total nesting for each nested element (ie, you could have, in Case 3, a top level object with 3 matrices at the lowest level in the first nested element and another with only 2 matrices) which will allow you to say the 'skeleton' or 'framework' of each nested array is the same?

Is the attached anywhere in the right ballpark?

Stuart

1-Visitor
May 28, 2012

Thanks for your response!

I feel I need a signature only so that I could evaluate the specific symmetry I'm looking for (by this symmetry I mean type 1, 2, 3, 4... in the previous post).

Because in the end there will be only a boolean function like IsThisObjectSymmetric(M) .

Here are a few examples

examples.jpg

It is hard for me to describe in words, but there has to be like this perfect tree-like symmetry (number 2 is acceptable because further nesting inside the deepest matrix does not matter).

It might be sufficient to split and manipulate the result of your shapeOf() function in order to evaluate this symmetry, but it is very late in my country, I need some sleep and continue mywork tomorrow.

Best regards.

Edit:

I decided to express the actions which are done by my function in this particular situation:

info.jpg

IsThisObjectSymmetric(C)

If it's a string, scalar or one row matrix (this includes one item array) instantly return false (not the case here).

If it's at least 2x2 matrix instantly return true (not the case here).

If it's a vector continue through its elements (A and B in this case):

If we find a string, scalar or one row matrix instantly return false (not the case here).

If we find matrices of equal size return true (not the case here).

If we find vectors of equal length continue through all of their elements (M1-M6 in this case):

If inside we find a string, scalar or one row matrix instantly return false (not the case here).

If inside we find matrices of equal size return true.

23-Emerald V
May 28, 2012

Pranas Pranas wrote:

Thanks for your response!

I feel I need a signature only so that I could evaluate the specific symmetry I'm looking for (by this symmetry I mean type 1, 2, 3, 4... in the previous post).

Because in the end there will be only a boolean function like IsThisObjectSymmetric(M) .

Here are a few examples

It is hard for me to describe in words, but there has to be like this perfect tree-like symmetry (number 2 is acceptable because further nesting inside the deepest matrix does not matter).

It might be sufficient to split and manipulate the result of your shapeOf() function in order to evaluate this symmetry, but it is very late in my country, I need some sleep and continue mywork tomorrow.

Best regards.

Edit:

I decided to express the actions which are done by my function in this particular situation:

IsThisObjectSymmetric(C)

If it's a string, scalar or one row matrix (this includes one item array) instantly return false (not the case here).

If it's at least 2x2 matrix instantly return true (not the case here).

If it's a vector continue through its elements (A and B in this case):

If we find a string, scalar or one row matrix instantly return false (not the case here).

If we find matrices of equal size return true (not the case here).

If we find vectors of equal length continue through all of their elements (M1-M6 in this case):

If inside we find a string, scalar or one row matrix instantly return false (not the case here).

If inside we find matrices of equal size return true.

Unfortunately, I don't have time to look at it further for a day or so, but I would just like to say "My Brain Hurts".