The Daily CLAD

Community Browser
cancel
Showing results for 
Search instead for 
Did you mean: 

Re: CLAD2017 - Fundamentals - Why do you have to be so negative

SercoSteveB
Active Participant

What is Numeric Value Out following execution of the VI?

 

Index Array Negative.png

 

a) -1

b) 0

c) 9

d) NaN

Comments
hemasagar
Member

Here the answer is C,

what ever the negative index value we are giving it is going to take the"Index 0" nearest to any negative index.

crossrulz
Knight of NI

C

The negative index will just return the default for the data type (0 for numerics).  And it will just increment from there, so the second index will actually be index 0, giving 9.


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
Vinay_Kumar_M_S
Member

C

nik35324
Member

C

mini09
Active Participant

C

qubirt
Member

C

Matt-A.
Member

C, what they said above. 

SercoSteveB
Active Participant

Answer: C.  Nice one all.

 

Nice explanation from crossrulz.

A.Bernau
Member

C

ChristineM
Member

Can someone help?  This actually looks like the Numeric Value Out is connected to the second row which would make (by default) Index 0, therefore 9.  When I connect the Numeric Value Out to the first row (index -1), I get 0 every time, not 9.  Please help.

SercoSteveB
Active Participant

Hi CristinaM

It's all about the index.  If you specify an index that is outside of those that are valid for the input array (valid range for the input array in the question is 0 to 5 inclusive).  I chose an index of -1 in the question but you would have got 0 returned by Index Array for every index outside of 0 to 5.  You get 0 because that is the default value for a numeric in LabVIEW.  If LabVIEW can't work out what the value needs to be or you have not specified what the value should be, LabVIEW will use the default value for the data type.

 

Here are some early The Daily CLAD posts that look at default values (oh the nostalgia)!!

 

https://forums.ni.com/t5/The-Daily-CLAD/For-loop-iteration-control-6/ba-p/3473603

https://forums.ni.com/t5/The-Daily-CLAD/For-loop-iteration-control-4/ba-p/3473385

https://forums.ni.com/t5/The-Daily-CLAD/Case-Structure-output-tunnels/ba-p/3474191

 

Steve

Hesham_Hassanein
Member

So, what if the index was 10?. 

crossrulz
Knight of NI

That would be outside of the array range, so you would get the default value, ie 0.


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
Hesham_Hassanein
Member

So, if the index is less than zero i will get the first element of the array, and if the index is greater than array size i will get zero?

crossrulz
Knight of NI

Nope.  If the index is outside of the range of the array (negative or greater than the last element's index), you will get the default value.

 

For this question, -1 was for the first input on the Index Array.  But what was actually being used was the second.  As you drag the Index Array, each input auto increments from the previous.  So with the first being index -1 (which will result in 0), the second will auto-increment to 0 (which will result in the first element in the array).


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
rak84
Member

c

istan0227
Member

C