LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Replace multiple array value

Solved!
Go to solution

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

 

HanaHumairah_0-1682872565855.png

 

Greetings

Hana

 

0 Kudos
Message 1 of 9
(1,029 Views)

Your array needs to be in a shift register, else you start from scratch with every new iteration.

 

altenbach_0-1682873280051.png

 

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:

 

altenbach_1-1682873503015.png

 

0 Kudos
Message 2 of 9
(1,026 Views)

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.

0 Kudos
Message 3 of 9
(1,023 Views)

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:

  • Change the "0, Default" case to simply "Default".  Bring that wire out of the Case Statement and wire it to the right edge (creating an Indexing Tunnel if it's not already there).
  • Create a separate Case Statement for every number you want to change.  If you want to make an input of "1" give you "50", make a "1" case and put the constant "50" inside that Case, wiring it to the "Last Value" tunnel on the right edge of the Case Structure (which is already wired to the Indexing Tunnel of the For Loop).
  • Repeat for all other changes you want.

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

0 Kudos
Message 4 of 9
(1,017 Views)

Such an simple mistake 🤦🏻‍♀️. I need to learn more about labview structures.

Thank you for your suggestion.

0 Kudos
Message 5 of 9
(1,013 Views)
Solution
Accepted by topic author HanaHumairah

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

 

altenbach_0-1682874388190.png

 

0 Kudos
Message 6 of 9
(1,012 Views)

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.

0 Kudos
Message 7 of 9
(1,008 Views)

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

0 Kudos
Message 8 of 9
(997 Views)

@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

0 Kudos
Message 9 of 9
(878 Views)