09-09-2010 02:45 AM
Hi,
working on this problem I was using (as usual) the PlotXY command for debugging, as follows:
plot_handle=PlotXY(panel_handle,PANEL_GRAPH,x,y_l,1001,VAL_DOUBLE,VAL_DOUBLE,VAL_THIN_LINE,VAL_NO_POINT,VAL_SOLID,1,VAL_RED );
Nothing spectacular besides the fact that the plot shows only zeros if the y array includes NaNs.
This is (at least) a non-documented feature....
If the data array consists of say 100 NaNs and 900 valid numbers I would have expected the function to display the 900 valid numbers. Also one could have expected an error but the function returns a valid plot handle.
Is there no possibility to display the valid numbers?
Thanks,
Wolfgang
Solved! Go to Solution.
09-09-2010 02:19 PM - edited 09-09-2010 02:21 PM
Wolfgang,
The expected behavior is that the valid points are plotted and the NaNs are skipped. But note that, if you choose a line plot, you need to have at least two consecutive valid points, otherwise you will see no line segments at all. You might obtain a better display if you use VAL_CONNECTED_POINTS or VAL_SCATTER.
Also, NaNs don't contribute to the new axis limits, if your axes are autoscaled. Your X-axis range seems to be (-10,0.8). If it's being autoscaled, might that be the extent of your x-data, considering only the valid points? And are all you valid y-values 0? Note that NaNs should simply be skipped -- they should not become 0. Therefore, a flat line of zeros is definitely unexpected.
Also, since this is an XY plot, all it takes is for one of the two values at a given index to be a NaN for the entire point to be skipped.
Luis
09-09-2010 03:46 PM
Hi Luis,
Thanks for your reply! Indeed I am pretty sure that the y array consists of a large number of consecutive valid numbers that are different from zero, however it starts with NaNs. I will export the array and upload it tomorrow for inspection. The x array is fully valid and covers the range displayed by the graph (autoscale).
Wolfgang
09-10-2010 02:17 AM
Hi Luis,
so after checking everything twice I can tell you that I did not see the expected behavior... I have even tried scatter points
The interesting thing is that the graphical array view works as you expected it to work, I am attaching the two views below. So in one dimension the CVI plot routines are able to deal with NaNs, but not the two dimensional PlotXY version. I am also attaching the two data sets allwoing you to confirm this behavior...
Thanks, Wolfgang
09-10-2010 02:42 PM
Thanks, Wolfgang.
I do see a problem, but I'm still not convinced that the problem is in the graph control. When I took your data and tested it, I saw the same flat line you did. But in looking at it some more, I noticed that I was actually passing zeros to the plotting function. I used FileToArray to read the data from your files, and it seems as if it is this function that is not handling NaNs very well.
Here's the code I used:
FileToArray ("x.txt", x, VAL_DOUBLE, 1001, 1, VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_COLUMNS,
VAL_ASCII);
FileToArray ("y.txt", y_1, VAL_DOUBLE, 1001, 1, VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_COLUMNS,
VAL_ASCII);
PlotXY (panel, GRAPHTEST_GRAPH, x, y_1, 1001, VAL_DOUBLE, VAL_DOUBLE, VAL_THIN_LINE,
VAL_SMALL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
However, if I replace the second FileToArray call with the code below, which approximates the values that were actually in y.txt, it is plotted correctly:
for (i = 0; i < 1001; i++)
if (i < 836)
y_1[i] = NotANumber();
else
y_1[i] = 0.65 + 2 * (i - 836) / 165.0;
So, my question is, are you also writing and then reading the date before plotting it, or are you plotting it directly after you obtain it from the GaussHG function?
Luis
09-10-2010 03:39 PM
Hi Louis,
Thanks for your investigations!
I am not writing or reading the data to or from a file. The code actually is just the loop to calculate the vaules
for ( index = 0;
index <= 1000;
index ++ )
{
x [ index ] = -10.0 + index * 0.0108;
y_1 [ index ] = GaussHG ( x [ index ], 0.5, 2.0, 1.5 );
}
and the command to plot them
plot_handle=PlotXY(panel_handle,PANEL_GRAPH,x,y_l,1001,VAL_DOUBLE,VAL_DOUBLE,VAL_THIN_LINE,VAL_NO_POINT,VAL_SOLID,1,VAL_RED );
that's all...
if you wish, I can upload the complete project (tomorrow...)
Wolfgang
09-11-2010 07:55 AM
Hi Luis,
it's embarassing and I ought to wear glasses... you were right, the plotxy function is behaving properly as long as the user is displaying the correct values... stupid me, I was calculating y_1 but displaying y_l, could not have been much worse...
Sorry for the false alarm concerning PlotXY, but the raw data obtaine from GaussHG still look odd...
Wolfgang
09-13-2010 11:46 AM
Ah, that's good. At least I know that the plotting fuctions are okay. But I still think there's a problem with FileToArray, which I need to look into sometime. Maybe those functions just don't support NaN. But when I saw the "NaN"s in your file, and since I was assuming that you had created those files with ArrayToFile, I thought this might also be a bug. You say you haven't read or written any files. So how did you create those two files?
By the way, soon someone (not me) should be looking into the specifics of the problem you're having with GaussHG.
Luis
09-13-2010 01:34 PM
So how did you create those two files?
Hi Luis,
for exporting the data I was using the variable window - some time ago you told me about the possibility to export arrays to a file
Wolfgang
09-13-2010 06:08 PM - edited 09-13-2010 06:09 PM
Oh, man.