Jump to content


Photo
- - - - -

Short out an array according to the elements of another array


  • Please log in to reply
6 replies to this topic

#1 Ano Ano

Ano Ano

    Very Active

  • Members
  • PipPipPip
  • 97 posts
  • Version:LabVIEW 2010
  • Since:2009

Posted 15 June 2012 - 06:21 AM

Hello,

I have the following situation:

First array:
1
2
3
4
5
6
7
8
9
10

Second Array:
3 0.01
6 0.08
7 0.03


and I want to create a Third array:

1
2
3 0.01
4
5
6 0.08
7 0.03
8
9
10


Any suggestions on who to do it?
Thank you in advance

#2 Maite

Maite

    Active

  • Premium Member
  • 23 posts
  • Version:LabVIEW 2010
  • Since:2011

Posted 15 June 2012 - 07:43 AM

When you say
1
2
3
...
and
3 0.01
6 0.08

Do you mean that in the index 3 of the first array do you want to place the index 3 of the second one. Or for the value 3 of the first array you want to place the index 3 of the second??

#3 Aristos Queue

Aristos Queue

    LV R&D: I write C++/# so you don't have to.

  • Premium Member
  • 2,620 posts
  • Location:Austin, TX
  • Version:LabVIEW 2011
  • Since:2000

Posted 15 June 2012 - 08:00 AM

Ano Ano:
These sorts of questions always work best if you can post your best attempt so far and let us help you fix it. If nothing else, go ahead and build the front panel that you want so that everyone is clear what data types you're trying to build up.

This sounds like a homework question, and the community will help, but it won't write it for you. Give us something to start with and then we can point you the right way.

#4 Ano Ano

Ano Ano

    Very Active

  • Members
  • PipPipPip
  • 97 posts
  • Version:LabVIEW 2010
  • Since:2009

Posted 15 June 2012 - 09:40 AM

Hello,

Thank you for your prompt reply.

Maite: I want to take the value from the second column of the second array and place it in a second column on the first array at the same location as it was in the second array.

Aristos Queue: No this is not a homework. I am too old for school & University:P. It is just that the mind tends to stop when it encounters a problem on simple logic:P


I am attaching my code, which seems to do the job (finally). Please have a look and if there is any better way of doing it please suggest it!

Thank you in advance.

Attached Files


Edited by Ano Ano, 15 June 2012 - 09:41 AM.


#5 jcarmody

jcarmody

    The 500 club

  • Premium Member
  • 789 posts
  • Location:North Carolina, United State, Earth
  • Version:LabVIEW 2012
  • Since:2007

Posted 15 June 2012 - 10:19 AM

[...]

Any suggestions on who to do it?
Thank you in advance

I was so hoping that I could be the first person to respond to this. :D

Resistance is Mandatory

No rulers
No masters
NO CONSENT

 


#6 rolfk

rolfk

    LabVIEW Aficionado

  • Premium Member
  • 2,045 posts
  • Location:Netherlands
  • Version:LabVIEW 2011
  • Since:1992

Posted 15 June 2012 - 11:41 AM

Hello,

Thank you for your prompt reply.

Maite: I want to take the value from the second column of the second array and place it in a second column on the first array at the same location as it was in the second array.

Aristos Queue: No this is not a homework. I am too old for school & University:P. It is just that the mind tends to stop when it encounters a problem on simple logic:P


I am attaching my code, which seems to do the job (finally). Please have a look and if there is any better way of doing it please suggest it!

Thank you in advance.


Why would you use string arrays, if the example you gave in your first post only contains numbers? Also I think your data structure design is highly flawed, if the data in the first post is all you want to sort. What you should look at is to use a 1D array of integers for your first array and an 1D array of cluster containing an integer and a float for your second array and the result.

#7 Slacter

Slacter

    Active

  • Members
  • Pip
  • 10 posts
  • Location:Dublin, GA
  • Version:LabVIEW 2011
  • Since:1996

Posted 03 July 2012 - 08:39 PM

The sample assumes that the Data Array Col 1 values are found in the same order that they would appear in the Main Array. Try swapping your 6 and 7 position and you'll find the 0.08 and 0.03 don't populate correctly.

How would you handle duplicate Data Array values in Col 1? The existing code uses only the first found and ignores the rest. Would you want to change to the last found, or do you need to keep track of all instances?

In case you're up for the challenge, the intended functionality can be obtained using the following:
  • 2 - Index Arrays
  • 1 - Search 1D Array
  • 1 - Replace Array Subset
  • 1 - For Loop
  • 1 - Case Structure
FYI: The functionality using the above would use the last found occurrence and keep only that value. If data loss is not desired, then a little rethinking is in order.