The Daily CLAD

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

Re: Array Manipulation Madness

SercoSteveB
Active Participant

What are the contents of Array Out following execution of the (pencil and paper required) VI?

Array Manipulation Madness 11_06_2014.png

a) A 1D Array containing {1}

b) A 1D Array containing {2}

c) A 1D Array containing {4}

d) A 1D Array containing {8}

Comments
Not applicable

I'll go with C).

We were looking at the Rotate 1D Array function in class today, to replace a multi-element shift register, as a means of keeping a running average in an array.May have to turn it into a question.

LordNobady
Member

C
Must admit that i have never used the rotate and decimate array.


Learning LabVIEW since January 2013
nik35324
Member

C.

crossrulz
Knight of NI

C


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

C.  I've used rotate, but never decimate.  I had to look up what decimate did.

Not applicable

Here is the code I wrote for the class. The multi-element shift-register is replaced with an array of fixed size; 5 elements in this example.The array is rotated by 1 element and a new data item added. This over writes the oldest piece of data (which was rotated). I think the point by point mean vi uses a similar principle.

Rotate Array screen shot 2.png

crossrulz
Knight of NI

For this situation, I prefer to keep track of which element to replace instead of shifting the array.  Haven't done any benchmarks, but for large arrays this should be faster.

Moving Average.png


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
SercoSteveB
Active Participant

I can see that multiple element shift registers reduce the ease with which the code can be scaled, but has anyone got any other reasons why we would prefer to go with something like as shown from DavidCorney & crossrulz?

A third alternative from me:

Alternate Approach.png

crossrulz
Knight of NI

There is also the memory reduction by keeping the array yourself.  In order to do a mean, you are building an array anyways.  By having the multi-element shift register and then build array, you are basically doubling your memory usage.  Using more memory usually equates to slower processing.

But Steve's alternative doesn't help this since he is reallocating the array with the Delete From Array and the Insert Into Array.

But scalability is by far the greatest reason to keep it in an 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
clendon.gibson@canrig.com
Member

The three alternatives to the CLAD question are all easier to read. The intent of each is clear. DavidCorney has even commented his example. I would have more faith that a junior programmer could correctly enhance or debug the alternates then the CLAD question. (It isn't clear to me why you would perform the CLAD option in production code.)

In a word, maintainability.

To be fair though, a CLAD question's intent is not to scallability or maintainability.

SercoSteveB
Active Participant

Answer: C.  Nice one DavidCorney, LordNobady, nik35324, crossrulz & MrStevenUND.

Some good stuff in this thread, nice one DavidCorney & crossrulz.  It depends on the application type but for the stuff we do, scalability and maintainability have precedence over squeezing every last bit of speed from an application.

mini09
Active Participant

Hi friends,

I go with answer A. Since the decimate array is extented to 8 outputs the output array may have only one element at this case and it's 4.

crossrulz
Knight of NI

gnshmrthy wrote:

I go with answer A. Since the decimate array is extented to 8 outputs the output array may have only one element at this case and it's 4.


                   

If you think there is only one element and it is 4, then why isn't your answer C?


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
mini09
Active Participant

Apologies crossrulz, my mistake.

Agree with your answer..

crossrulz
Knight of NI

I just didn't want you to have a wrong answer when you did all of the logic correctly.


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
mini09
Active Participant

Appreciate your guidance and feel happy to have your suggents.

hemanths
Member

I think the Perfect CLAD question. 1 Question 4 functions