From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

Sum a loop calculated data and using less than in calculation loop

Hi!

I'm new to labview and i troubles with visual programming. I need a 24 hour diagram and i trying to do that with for loops. So i have 2 loops. First add x value to 0 N times. Second subtract the calculated data by y value N times. Yes, it will look like a triangle. I have two problem with that:

#1 Cannot sum the calculated data, so it just subtract from x value by y value N times that cause negative data.

#2 Cannot use 'Less than' in adding. I mean I only want to add x to x again if it less than z. Because if the subtract would successfuly done it will have remain data (not zero) causing more and more higher x value than it should be. I'm learning in school c so i can show what i need.

 

x , y, o, and k are the values i have.

int x;

for (int i=0; i<o; o++)

{

  if (x<u)

  {

    x=x+x;

  }

  else

  {

   x=x-k;

  }

for (int i=0; i<o; o++)

{

 x=x-y;

}

 

Sorry for this question but i didn't see any solution for that. Please if u see any mistake in my english correct it, i'm still learning it!

Thanks a lot,

Domonkos

0 Kudos
Message 1 of 4
(1,971 Views)

Hi Domonkos,

 

I'm new to labview and i troubles with visual programming.

Then I recommend the Training section in the header of this LabVIEW board!

 

for (int i=0; i<o; o++)
{
 if (x<u)
  {
   x=x+x;
  }
 else
  {
   x=x-k;
  }
}

Here you need a simple FOR loop with a case structure (IF-THEN-ELSE) inside.

Btw. should the loop not be called like "FOR i=0; i<o; i++"???

 

for (int i=0; i<o; o++)
{
  x=x-y;
}

This simply is the same as x:=x - o*y. No loop needed…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 4
(1,965 Views)

I am not sure I fully understand what you are after (a 24 hour diagram?) but this is the first thing off the top of my head.

 

24hr.png


========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 4
(1,960 Views)

@Domonkos wrote:

I need a 24 hour diagram


First step: Define what you mean by a "24 hour diagram"! I am not familiar with the term but I suspect there is more to it than a simple scalar numeric answer. A simple numeric is typically not a "diagram" and definitely does not "look like a triangle".

 

Now to your code: Your code image makes no sense and has no obvious relation to your problem. Why is the loop count 46? Whenever you are autondexing out of a loop and autoindexing back into a loop (and nothing else really), the loops can be combined into one. You need to understand the initializer terminal of a feedback loop, it will only get read on the first call, so all remaining array values of your array will be lost irreversibly. If you have x, y, o, and k, you should label terminals (or wires for temporary values isolated to the diagram) accordingly to make the code obvious to read. Your formula also contains a "u" that is never defined. Where does it come from? A truncated image fragment is NOT useful to get help, so attach a VI instead.

0 Kudos
Message 4 of 4
(1,941 Views)