LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

labview / array function inside for loop implementation

Hello, I have gone through basic tutorials and documentations.

But Cant find out solution for implementing below array function(y= y +(A[i]* T);) inside a loop. please hlep me out.

 

Float  y=0;

Float T=273;

A= { 1,2,3,4};

For (int i=0; i<=4;i++)

{

y= y +(A[i]* T);

}

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

I see you already have the auto-indexing tunnel for the array and the For Loop.  That is a good start.

Store the y value in a shift register that is initialized to zero.  (Shift registers are also a very important LabVIEW concept.)

 

All the rest is very basic math calculations and you should be able to figure out.

 

I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours

0 Kudos
Message 2 of 9
(3,370 Views)

try to write your code if you code not this code help you 
but Deliberately there is a mistake inside the code try to find it it will help you to understand better about code function in labview for your aim

0 Kudos
Message 3 of 9
(3,349 Views)

Who needs a for loop?  LabVIEW can work on the arrays directly.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 9
(3,331 Views)
Crossrulz,
Also your answer is correct and better way to find the answer
but here important thing is not the answer of algorithm is algorithm itself
because it is for training and learning and your answer is not what algorithm should be
you produce array of number form 1 to 4 but as you see above you have to create it by auto indexing and by algorithm not manually
0 Kudos
Message 5 of 9
(3,291 Views)

@prem.s241 wrote:

Hello, I have gone through basic tutorials and documentations.

But Cant find out solution for implementing below array function(y= y +(A[i]* T);) inside a loop. please hlep me out.

 

Float  y=0;

Float T=273;

A= { 1,2,3,4};

For (int i=0; i<=4;i++)

{

y= y +(A[i]* T);

}


Look at your For loop description.  While I'm not a C/C++ expert, I think the formulation "For (int i=0; i<=4;i++} will run 5 times, with i taking on the values 0, 1, 2, 3, 4.  Now look at your array A -- it only has 4 values.  Is this a bug in the Question?

 

What happens inside the loop?  One way of looking at it is that you are adding up a cumulative sum (initializing y to 0 and then adding A[i]*T each time through the loop).  But if you have the Array A, you can multiply it by a scalar, T, and sum the elements of the Array with the Sum function found on the Numeric palette.

 

Since you are giving the values of A and T, the problem is (almost) trivial, as you would learn when you spend time with the Tutorials.  Form the A array, form the T constant, multiply them, sum the array element, save as the answer "y".

 

So I agree with Crossrulz.  It is always better to look at the Entire Problem, think a bit about it, and be willing to take the "simpler, better" solution.  [A Famous Story concerns Gauss being asked to sum the numbers 1 through 100, and writing down the answer, 5050, "by inspection" instead of tediously adding 1 + 2 + 3 ...].

 

Bob Schor

Message 6 of 9
(3,272 Views)
Hatef,

I think you should have placed a period after 'better way to find the answer' and skipped all of the rest of your comment.
0 Kudos
Message 7 of 9
(3,253 Views)

Cat Very Happy
Dennis_Knutson

Maybe you are right.
But if we want to help one newer in LV programing I do not think giving easy and fastest way to solve one simple programing is right way 
because he will be loose some information that might they could be helpful for big algorithms 
what is your Idea to ask this person use that method you believe is best answer to present him to solve problem that require make large arrays ?! his question exactly is to find a way make array and do some operation on it not solving the answer
I think the totally the best answer  that could be helpful for this friend is what Bob_Schor sent

totally the best answer  that could be helpful for this friend is what Bob_Schor sent

totally the best answer  that could be helpful for this friend is what Bob_Schor sent

best regard,
Hatef

 

0 Kudos
Message 8 of 9
(3,233 Views)
labview / array function inside for loop implementation
what this topic telling you ?!
0 Kudos
Message 9 of 9
(3,221 Views)