Jump to content

Short out an array according to the elements of another array


Recommended Posts

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
Link to comment

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
Link to comment

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.

Link to comment
  • 3 weeks later...

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.

Link to comment

Join the conversation

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

Guest
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.