11-02-2016 02:17 PM - edited 11-02-2016 02:20 PM
I can do this in MatLab/MATLAB:
When I try to wire multiple inputs into a case structure then I get wire errors.
These are limited cases, not exhaustive. These are numeric inputs, not text or boolean. There has to be a way where I can wire an array or such into a case structure.
What am I doing wrong?
Solved! Go to Solution.
11-02-2016 02:29 PM
Hi EngrStudent,
There isn't a way to wire an array or multiple numerics into a case selector.
The first suggestion that comes to mind would be to convert the three numbers to strings and then concatenate them all into one string. Then you could wire the string into the case structure and program each of the possible cases.
This can easily be done using the string conversion VI's.
11-02-2016 02:31 PM
@GrayGrey - inelegant, but on it. Will let you know how it goes, and kudo appropriately.
11-02-2016 02:42 PM
Case structures accept integer numeric types as selectors.
One possibility would be nested case structures with a, b, and c wired to different ones. Another method would be to do some simple math to combine the three inputs into a single numeric value and use that as the selector for one case structure. The difficulty of this approach depends on the ranges of possible values for the inputs.
Lynn
11-02-2016 03:27 PM
It is extremely inelegant, but you can do the exact equivalent code with the Select function and comparators. Note that this code has an "unspecified case" ("None of the above") which you have not defined, but I defined as -12345.
Note -- I absolutely do not recommend doing this in "real code". Think about what you really want to do (which is almost certainly not "encode a very limited set of three-digit numbers").
Bob Schor
11-02-2016 03:52 PM
Cases can display in Hex
11-02-2016 03:55 PM
Thanks, Jeff. A very elegant and simple implementation of the concept I had in mind.
Lynn
11-02-2016 03:57 PM - edited 11-02-2016 03:58 PM
@Jeff - I have 2015 so the snippet isn't transferring. What is the name of the vi that you connect both "A" and "B" to?
11-02-2016 04:07 PM
That's "Join Numbers", found on the Numeric Palette under Data Manipulation. And it definitely is elegant, and does not let you make the mistake of "Oops, there's a case I didn't consider", as the numeric Case statement requires a Case for every possible numbers, hence the "Default" Catch-All (a.k.a. a "Terminal ELSE").
Bob Schor
11-02-2016 04:11 PM
It is a shame that this doesn't accept boolean inputs.