取消
显示结果 
搜索替代 
您的意思是: 

Need help with 2D array

已解决!
转到解答

Hi All,

I am working with a 2D array which stores numeric values. Let me explain my problem with an example.

consider a 2D array as shown in the attached image(input.png). the elements in the 2nd row are already present

in the 1st row. How can i obtain a new 2d array in which the rows, which are already a subset of some other

row, are not present i.e., each row has unique elements only.(output.png)

 

Thank you for the help.

Regards

Aveo 

下载全部
0 项奖励
1 条消息(共 16 条)
4,833 次查看

Are the non-duplicate element values always increasing in memory order? That would simplify certain things.

 

I would (1) reshape to a 1D array, (2) remove all duplicates, (3) then reshape back to a 2D array of the original size.

 

 

0 项奖励
2 条消息(共 16 条)
4,822 次查看

 

Hi,

Thank you for the quick reply.

YES, the non-duplicate element values always increase in memory order.

However the 2d array could be like this also:      1  2  3  4  5  6  8  9

                                                                      2  5  6  8  0  0  0  0

                                                                      5  8  0  0  0  0  0  0 

                                                                      7  0  0  0  0  0  0  0

 

Regards

Aveo                               

0 项奖励
3 条消息(共 16 条)
4,807 次查看

@aveo wrote:

 

YES, the non-duplicate element values always increase in memory order.

However the 2d array could be like this also:      1  2  3  4  5  6  8  9

                                                                      2  5  6  8  0  0  0  0

                                                                      5  8  0  0  0  0  0  0 

                                                                      7  0  0  0  0  0  0  0                        


Well, in this example they don't increase in memory order (e.g. 8 occurs before the first 7). Do you want them sorted in the output array in this case or in the original order of first occurrence. (It does not help if you describe a special case, but then fail to show what the desired output would be ;))

 

If you want the output sorted, do bascally what I suggested above.

 

Remove all duplicate elements or elements that are zero. (here are some ways to do it, some are much more efficient ;)). Of course you would need to add code to also remove zeroes. Should be trivial to change. Good luck. 😄

 

0 项奖励
4 条消息(共 16 条)
4,783 次查看

Thanks for the suggestions. 🙂 

I will implement them and post it here.

Regards

Aveo 

0 项奖励
5 条消息(共 16 条)
4,775 次查看

Hi Altenbach,

Thanks for your suggestions.

I have created a vi (Find_Overlapping_Rows.vi) that does what i require, however in a different way.

can you suggest any more improvements in it?

Thanks.

Regards

Aveo

0 项奖励
6 条消息(共 16 条)
4,722 次查看

Put some typical numbers in the input array, make the current values default, save and attach the toplevel VI once more.

 

... and yes, this looks way too complicated. Can there be negative values too?

0 项奖励
7 条消息(共 16 条)
4,702 次查看

Here's what I had in mind....

 

 

0 项奖励
8 条消息(共 16 条)
4,693 次查看

Hi Altenbach,

I am attaching the vi again with an initialized array. 

I put the same array in your vi and the results are different. 

If you will take a look at the array the 6th row(starting from 0) has 10 and is not a subset of any other row.

However in Find_Overlapping_Rows_MODCA.vi it is not coming as i want it.

And there cannot be negative values. 

Thanks.

Regards

Aveo

 

0 项奖励
9 条消息(共 16 条)
4,667 次查看

aveo wrote:

However in Find_Overlapping_Rows_MODCA.vi it is not coming as i want it.


Then you need to define better what you want. There are millions of possible results that are different from what I did, so we cannot narrow it down at all given the vague information. What is the exact result you want from your VI when run with the current default input data?

 

Maybe you should manually fill the output array with the exepcted result and also make it the default.

0 项奖励
10 条消息(共 16 条)
4,658 次查看