Jump to content

Short out an array according to the elements of another array


Recommended Posts

Posted

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

Posted

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??

Posted

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.

  • Like 1
Posted (edited)

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.

Array Sorting.vi

Edited by Ano Ano
Posted

[...]

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

Posted

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.

  • 3 weeks later...
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.