Align Data With 1-Element Array


Recommended Posts

I need to align (by time) two data series in a table. This is no problem when both series contain at least 2 data points. However, if one series contains only one data point, I cannot find a solution to it.

 

Example:

ch1={1,2} (with timestamps associated)

ch2={10} (with same timestamp as ch1[0])

 

What I need is the following table (the hyphens may be replaced by anything showing that there is no data):

ch1 | ch2

=========

 1  | 10

 2  |  -

 

What I actually get with align(ch2, ch1, 1) is this:

ch1 | ch2

=========

 1  | 10

 2  | 10

 

As soon as ch2 gets more than 1 element, I get the result I expect. I believe that the problem is related to the fact that 1-element arrays are not treated as arrays, so ch2 actually is not {10} but just 10.

Is there a solution to this problem?

Link to comment
Share on other sites

I'm not completely sure.  Here are some ideas:

 

1) do you have the align threshold parameter set correctly?

2) change your 1 element array into a 2 element array where both rows have the exact same value and time stamp.

 

I can probably come up with more ideas, but I think maybe #2 will work.

Link to comment
Share on other sites

@1) The alignment is not critical because the data in ch2 is entered manually, and the timestamps set to exactly the corresponding entry in ch1. 1s should be just fine.

 

@2) Thank you for this suggestion/workaround. My working solution is now to "duplicate" ch2, so each row exists 2 times, and either the array is empty (which is no problem here) or it is 2 or more elements long.

However, this is indeed just a workaround and not optimal with respect to memory and processor usage. Probably not a major problem in my application, but it would be much better (and more consistent) to distinguish between scalars and vectors (no matter whether the vector has 1 or more elements). In other words, only variables declared as a vector should be vectors, but then, they should always be vectors independent of their length.

Link to comment
Share on other sites

I took a look at the source code, and its actually explicitly coded that if the first parameter is an array with one element that it should place that value in for every element of the second parameter.  This was done a long time ago, but the reason for this I believe is that align() was originally designed for graphing, specifically XY graphs, and you can't graph an array with only one element.  

 

As to your comments:  There is no reason to duplicate every ch2 entry.  Just use:

 

if(numrows(ch2) == 1) 

   ch2[1] = ch2[0]

endif

align(ch2,ch1,1)

 

before the align.  Then you only do this in one small case, and the memory hit is only 16 bytes.

 

As for scalars vs vectors, DAQFactory considers everything an array, so we don't explicitly require you to declare something an array or scalar.  Especially since many scalars end up being arrays (think channels as they accumulate data).  There are some things that are different, for example if you do:

 

x + y

 

and x and y both have more than one element, then the resultant array is the same size as the smaller of the two (the extra elements are truncated), with each being the sum of the corresponding array element.  But, if either x or y has only one element, that element is added to every element of the other.  In other words:

 

{1,2} + {3,4} = {4,6}

 

but:

{1,2} + {3} = {4,5}

which is the same as:

{1,2} + 3 = {4,5}

 

because DF doesn't distinguish between 3 and {3}

Link to comment
Share on other sites

Yeah, I know that it's inefficient to just duplicate, and I would have done as you suggest if I had needed it in a sequence. However, the place where I need it is just a table as a screen element, so I need a compact expression which can be used there. And since my arrays/channels are not too big in this case, I decided to just duplicate ch2.

Link to comment
Share on other sites

  • 1 month later...

Hi,

 i am new to daq factory, i am trying to dispaly some comment ,when i place a cursor on the particular button,i know that it can done by using screen coordinates(x,y).but i am  not getting how to access these coordinates for dispaly help window.example: if we place cursor on device config icon,it display some text below that.the same thing i have to do here.please provide me the solution.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.