12-06-2021 09:17 PM
Hi,
I'm struggling to figure out how to take an array and assign a letter grade to the given value. The portion of the assignment I am trying to do right now is:
Determine the country’s “Grade” using the following scale;
A = <= 50 pounds / person
B = >50 & <= 100 pound / person
C = >100 pounds per person
This is what I have so far, the first loop is from the first part of my project and the second loop is what I am trying to do for this current part.
Currently my output only comes out for the first element of the array. Please let me know what I am doing wrong and how to fix it.
Solved! Go to Solution.
12-07-2021 02:00 AM
Hi Aman,
It's because you have the "last element" terminal on the output of your for loop. You should change it to "indexing".
Secondly, you can wire the numeric wire directly into the Case Selector of the Case Structure and define which case will be executed under which condition:
https://zone.ni.com/reference/en-XX/help/371361R-01/glang/case_structure/
You can check even the example how to use it in Example Finder -> Case Structure - Selector Data Types
12-07-2021 10:08 AM
@AmanAman wrote:
Hi,
I'm struggling to figure out how to take an array and assign a letter grade to the given value. The portion of the assignment I am trying to do right now is:
Determine the country’s “Grade” using the following scale;
A = <= 50 pounds / person
B = >50 & <= 100 pound / person
C = >100 pounds per person
(Sorry, cannot see your VI because I don't have LabVIEW 2021 here. Consider "save for previous" or at least attach a picture)
12-07-2021 01:32 PM
Hi,
Thank you for your response. I just changed to output to "indexing" and now I do get multiple elements in my array. However it is only inserting the first element from the array into all the rows. Also I do not understand what you mean by "wire the numeric wire directly into the Case Selector of the Case Structure and define which case will be executed under which condition". I did what I understood from it and wired it accordingly is this correct? the output is the same regardless of the wiring to the case selector
12-07-2021 01:40 PM
Floating point numbers cannot be wired to the case selector, only integer numbers can. I also don't have LV 2021 installed so can't look at anything beyond the picture.
12-07-2021 01:41 PM - edited 12-07-2021 01:42 PM
A truncated code image is completely useless (except that it tells us that you have very little experience 🙂 )
Please show the entire code and all cases of case structures! Where's the loop? Where's the tunnel? Where do the wires come from? Where do they go?
Typically you would just threshold into an array of limits, round it correctly, and index into an array containing [A, B, C]. No need for case structures and range functions.
12-07-2021 01:47 PM
@Mark_Yedinak wrote:
Floating point numbers cannot be wired to the case selector, only integer numbers can.
Yes, they "can", but the result might not be what's expected 😄
12-07-2021 03:37 PM - edited 12-07-2021 03:46 PM
Expect the unexpected 😄
@Mark_Yedinak, you're right, I didn't notice he's using floating points.
Edit: I saved his VI in version 17, if you want to take a look. (Missing subVI is missing even in original attachment 🙂 )
For the author:
Yes, you have to pass the wire directly into the case selector, but as pointed by Mark, you shouldn't use it with the double data type. Either you can convert the floating-point into the integer or use integers from the beginning if you are working with non-floating-point numbers.
For how to use Case Structure with integers, the link from my first reply and/or the example in the Example Finder should help.
12-07-2021 06:30 PM
See if this can give you some ideas. (just a picture, so try to implement it. A good exercise). Note: No case structure! (Some things can be simplified, but start with that)
12-07-2021 06:36 PM
This gives the same result but is a bit more obscure. Try to figure out how it works 😄