cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Return a nested array from other nested array.

lvl107
20-Turquoise

Return a nested array from other nested array.

  Hello, Everyone.

Create a Function.PNG

  Need help to create a function U( ) as the above or a similar ?

  Thanks in advance for your time and help.

      Regards. Loi Le.

1 ACCEPTED SOLUTION

Accepted Solutions
Werner_E
24-Ruby V
(To:lvl107)

I have no idea what you are trying to do and why you would need a function returning two identical matrices.

The for loop in you local function U_ does not make any sense as the actual arguments of that function when you call it are just scalars (either 0 or 1).

Your function will return two identical matrices unless the first and/or last values in the argument vector are 0' or 1's because the loop for O runs from 0 to 1. Thats the reason for the different result in your third example.

As already said - I don't know what you are trying to do. I do not even know whether the green or the red result is what you expect and need. In you first question you demanded exactly that red result and now you are wondering why the two rows are different!?

EDIT: Just an afterthought: If the input matrix is [ 3 3 3 0 0  3 3 3 3 7 7 1 1 3 3 3 5 5], what do you expect as a result?

Are you expecting three different row vectors this time?

Perhaps [3 0  7 1 5], [0 3 7 1 5] and [0 7 1 3 5]?

If thats what you are after, what is the result for [ 0 0 0 1 1 3 3 0 0 1 1 1 2 0 0 0]?

Six rows?

[0 1 3 2]

[1 3 0 2]

[1 3 2 0]

[0 3 1 2]

[3 0 1 2]

[3 1 2 0]

View solution in original post

7 REPLIES 7
Werner_E
24-Ruby V
(To:lvl107)

Obviously duplicate scalars are discarded but you sure would have to provide criterions how and where to split your vector into two (ore more?) subvectors.

Werner_E
24-Ruby V
(To:lvl107)

Or are you rather searching for something simple like this?

lvl107
20-Turquoise
(To:Werner_E)

Thanks for your time and help, Stuart and Werner.

Werner, I follow the base of your hint ( Unique Function.)

Create a Function (2) .PNG

           I'm not sure the reason of the difference of the first row and the second row ( in red highlight )

           and need help with an explanation .

               Thanks in advance

                  Best Regards.

Werner_E
24-Ruby V
(To:lvl107)

I have no idea what you are trying to do and why you would need a function returning two identical matrices.

The for loop in you local function U_ does not make any sense as the actual arguments of that function when you call it are just scalars (either 0 or 1).

Your function will return two identical matrices unless the first and/or last values in the argument vector are 0' or 1's because the loop for O runs from 0 to 1. Thats the reason for the different result in your third example.

As already said - I don't know what you are trying to do. I do not even know whether the green or the red result is what you expect and need. In you first question you demanded exactly that red result and now you are wondering why the two rows are different!?

EDIT: Just an afterthought: If the input matrix is [ 3 3 3 0 0  3 3 3 3 7 7 1 1 3 3 3 5 5], what do you expect as a result?

Are you expecting three different row vectors this time?

Perhaps [3 0  7 1 5], [0 3 7 1 5] and [0 7 1 3 5]?

If thats what you are after, what is the result for [ 0 0 0 1 1 3 3 0 0 1 1 1 2 0 0 0]?

Six rows?

[0 1 3 2]

[1 3 0 2]

[1 3 2 0]

[0 3 1 2]

[3 0 1 2]

[3 1 2 0]

lvl107
20-Turquoise
(To:Werner_E)

(4).PNG

Create a Function (3) .PNG

                                       ( Unique Function.‌ )

  I got it. Thanks again for your time and help, Werner.

       Best Regards.

Werner_E
24-Ruby V
(To:lvl107)

  I got it.

?? Hmm, I am still clueless.

But there is an error in (my ?) Unique function. Replace the initial 0 by NaN to make it work correct.

StuartBruff
23-Emerald II
(To:lvl107)

By coincidence, we had a thread recently on one part of your problem, that is removing duplicate values whilst preserving their order of occurrence.   It looks like a chance to reuse some code here and add a couple of other functions that are generally useful (or, at least, I keep writing versions of them!):

I've used vdiff for calculating the difference between successive elements in a vector (but only when I've had another need for the 2 vectors!).  I frequently use the functional version of transpose to make vector display more compact by vectorizing it over a nested vector, as the example below hopefully demonstrates.

Stuart

Top Tags