Comparing two X,Y,Z structures and generating new one with added indexed values from Serial I/O.

mvesga's picture

Hi, I have an string of comma separated values coming from the Serial I/O which correspond to a 16x16 matrix Array. I'm breaking down the string into a Structure with 16 index members every 16 values, on a queue size of 16 (16x16). I'm struggling trying to generate a structure containing the 256 members (I'm only getting a structure of 34 members) from the array which then I would like to include (and match) to it's corresponding ordered position in an indexed X,Y,Z structure. Problem is that I won't always have the same amount of members in my X,Y,Z structure. So I would like to detect how many values are actually active on the 16x16 array and then generate a new structure of 4 members containing the matrix value + the X,Y,Z values for its' corresponding index position. My approach was to compare two sets of X,Y,Z Structures in order to generate a third structure that would be composed of the matching values within the two previously compared structures + the active array values passed through an iterator. Problem is I can't seem to pass on the queued values properly inside iterators; from a 16 sized queued structure of 16 members I'm only getting a structure of 34 members/iterations.

I'm using the following Javascript in order to accomplish this:

function (__structure s1d) main (__structure s2d, __index size, __number len) 
   var result = new Object();
   var j = 0;
   var f=0;
   q=new Array();
   for(var i=0;i<size;i++)   
   f="point00" + i;
   q.push(f); //pass the point names
      for(var n=0;n<len;n++)
   return result;

Given my limited javascript knowledge I haven't been able to achieve this. Would be great if anyone could point me in the right direction or know how to solve this. Any help would be highly appreciated! and would definitely earn some good karma points ;)

Sorting arrays and splitting arrays in Javascript's picture

Javascript help for novice coders like me!

Apart from the fact that the JS patch is temperamental — requiring restarts of QC application when it will not parse good script — I attempted to clear up some of the mysteries I had around working with 2D datasets in Javascript. Standard JS array methods that work for 1D arrays often don't work for more complicated array structures.

This composition has three demo JS patches for:

splitting a set of points into two sets (odds and evens by index), sorting an array of dictionaries by a common dictionary key (a-Z) & concatenating both internally created and inputed structures into one array

All the code is well commented, I hope it can save some of the suffering for others that the JS patch has given me. So let me know if it does and I will have been rewarded for posting it.