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

SOLVED
Highlighted
Pearl

## Return a nested array from other nested array.

Hello, Everyone.

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

Regards. Loi Le.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

## Re: Return a nested array from other nested array.

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]

7 REPLIES 7
Highlighted

## Re: Return a nested array from other nested array.

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.

Highlighted

## Re: Return a nested array from other nested array.

Or are you rather searching for something simple like this?

Highlighted

## Re: Return a nested array from other nested array.

Thanks for your time and help, Stuart and Werner.

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 .

Best Regards.

Highlighted

## Re: Return a nested array from other nested array.

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]

Highlighted

## Re: Return a nested array from other nested array.

( Unique Function.‌ )

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

Best Regards.

Highlighted

## Re: Return a nested array from other nested array.

 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.

Highlighted

## Re: Return a nested array from other nested array.

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

Announcements