04-30-2023 11:39 AM
Hey all. I'm new to labview and in the learning phase.
I have a question about replacing multiple array values.
I want to replace the array values if the values are 1 to 100 and 0 to 50.
I've created a case structure and put replace array subset inside case structure but when I execute the code only index 1 changes. I think something part is missing and I need your suggestion to make my code executable successfully. Thank You
Greetings
Hana
Solved! Go to Solution.
04-30-2023 11:52 AM
Your array needs to be in a shift register, else you start from scratch with every new iteration.
Of course most of your code does not make a lot of sense and count be done mush simpler!
Maybe, (just maybe!), all you need is the following:
04-30-2023 11:55 AM - edited 04-30-2023 12:09 PM
99% of of solving a problem is defining it.
@HanaHumairah wrote:
I want to replace the array values if the values are 1 to 100 and 0 to 50.
Can you explain what that means? If this is a logical AND, you want to replace if the values is 1..50, i.e. matching both conditions! OTOH, you are not saying WHAT you want to replace it with! Are these ranges or assignments?
If you want to replace all zeroes with 50 and all 1 with 100, you fail to tell us what should happen if the value is 3. Should that remain at 3 or change to 100 too?
Also note that your search always starts at the beginning and it can never ever find a duplicate value that comes later.
04-30-2023 12:01 PM
I'm not certain I understand what you want to do, but can comment on how you are doing it.
You know that if you put an Array into a For Loop, (by default) it comes in through an "indexing tunnel" (which, if you look closely, is a square box with a pair of brackets inside it (this is a pair of brackets inside curly braces -- {[]}). If you bring the (now slimmer) wire across to the other side of the For Loop and pass it out, it will (again, by default) go out as an indexing tunnel, and re-create the original array.
But while it is inside the loop, you can do things with its value. Pass the value into a Case Statement. It will create two Cases for you (with an I32), "0, Default" and "1". Here's what I recommend:
Your program is done, and will "do what you told it to do", replacing every "X" with "Y", and leaving everything else "as it was". Very simple, easy logic to see and understand.
Bob Schor
04-30-2023 12:05 PM
Such an simple mistake 🤦🏻♀️. I need to learn more about labview structures.
Thank you for your suggestion.
04-30-2023 12:06 PM
@altenbach wrote:
If you want to replace all zeroes with 50 and all 1 with 100, you fail to tell us what should happen if the value is 3. Should that remain at 3 or change to 100 too?
Here's is one possibility that replaces all 1 with 100, all 0, with 50, and leaves all other values unchanged.
04-30-2023 12:08 PM
It means a value of 1 for case structure 1 and a value of 0 for other case structure conditions. it has nothing to do with AND logic. And if the value is 3. It should remain value 3. Nothing need to change. Sorry if my explanation is not clear because I am not fluent in English.
04-30-2023 12:12 PM
@HanaHumairah wrote:
It means a value of 1 for case structure 1 and a value of 0 for other case structure conditions. it has nothing to do with AND logic. And if the value is 3. It should remain value 3. Nothing need to change. Sorry if my explanation is not clear because I am not fluent in English.
So since you want to inspect all elements, you should autoindex as shown. (You could create three cases : 0,1,default, with the default wires across, 1 containing a 100 constant and 0 containing a 50 constant.
05-01-2023 08:30 PM
@HanaHumairah wrote:
It means a value of 1 for case structure 1 and a value of 0 for other case structure conditions. it has nothing to do with AND logic. And if the value is 3. It should remain value 3. Nothing need to change. Sorry if my explanation is not clear because I am not fluent in English.
Go back and read my attempt to teach you exactly how to solve this problem yourself. You program (in the Case Statement) the numbers you want to "be different", and let the Detault case handle all the other number that you "want to remain the same". One While Loop, one Case Statement, and n+1 Case "labels", n for the number of "special cases" (0 becomes 100, 1 becomes 50, or whatever) and the remaining 1 for "default", or "everything else".
Try it. Program it yourself. See if it works. Learn LabVIEW by doing it yourself, trying, and learning from your own experience.
Bob Schor