From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search 1D array for all instances and add another array.

Solved!
Go to solution

Hello.

 

I am trying to make a program that makes a meal plan and shopping list for the week, from a set of predefined recipes.

The way it works is that I have a excel document with the different recipes, ingredients and how much of each ingredient. Then the program makes a list of X different recipes and combine all the ingredients to a shopping list.

 

So, in the end I have 2 arrays. One being a text array with the name of the ingredient and the other a numerical array with how much of each ingredient.

 

Here is my problem. I would like to delete duplicates on my text array and then add the numbers together on the numerical array. I will try to formulate an example below.

I have one text array with the items eg: [Milk, Flour, Sugar, Milk, Milk, Ketchup] and another with the numbers of how many pieces of the items I want to buy eg: [1, 1, 2, 3, 1, 1].

 

In this example I would like to sum up all the entries of milk, so I would end up with [Milk, Flour, Sugar, Ketchup] and [5, 1, 2, 1]. I hope this makes sense.

0 Kudos
Message 1 of 7
(2,224 Views)

Hi Marcus,

 

use a LUT (look-up table) based on variant attributes (or a map/set in LV2019).

See here

 

(A very similar question came up recently.)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 7
(2,208 Views)

How will you combine all of the different units of measurement that could be used for recipes and convert that into a store bought unit?  For example, milk is typically measured in cups or mL but it bought in gallons or liters.  If one recipe uses cups and another uses mL, you'll need a conversion factor to be able to combine them.  Just something to consider.

 

Is this a practical application that you plan to use at home or is it a school project? 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 3 of 7
(2,161 Views)
Solution
Accepted by MarcusNilsen

Hello Marcus,

 

Please find the attached VI that gives you the required solution.I have used a VI from OpenG Library and I have attached it too.

Hope it helps, Let me know if my understanding to your problem is right.

 

Thanks

Rahul

Click KUDOS and Mark as Solution to convey Thanks

 

Download All
0 Kudos
Message 4 of 7
(2,136 Views)

Hey aputman, that is a good point. I think that I will start with getting it to work with just being consistent with my units in my recipe spreadsheet and only using liters for milk and so on. 

 

This is just a fun project for home, but if it comes to work really well then I might use it to do my weekly meal and shopping plan.

0 Kudos
Message 5 of 7
(2,122 Views)

Hello Rahul.

 

Thank you so much, this does exactly what I asked for. thank you so much!

0 Kudos
Message 6 of 7
(2,117 Views)

Welcome. 

 

Thanks

Rahul

Hit KUDOS for Thanks

0 Kudos
Message 7 of 7
(2,109 Views)