Initializing a zero length wave

Hi,

In many of my tools I will initialize a wave with zero rows and as I run through the analysis I append data with a simple assignment:

make/o /n=0 result

result[numpnts(results)]={someValue}

and this work as expected.  I think in the past I extended this technique to handle 2 dimensional waves.

with

make/O /N=(0,2) results

setdimlabel 1,0,nm, results

setdimlabel 1,1,id,results

However with IP9 this does not seem to work.  Results is created but it is a 1 dimensional wave and if I try to redimension it the column numbers are grayed out and not available.  I could have sworn I have done this many a time in the past.  Has something changed or has my memory failed me.

Andy

What doesn't work? The 1D case is quite different from the 2D case; the 1D case is a wave assignment, the 2D case is setting dimension label. We actually make a special case of preserving the higher dimensions even when there are zero rows, exactly so that folks can set the dimension labels. I just tried it- you can set dimension labels.

In fact, I made a wave assignment analogous to your 1D case, and that worked too. Here is what I did:

make/O/N=(0,2) junk
setdimlabel 1,0,col1,junk
setdimlabel 1,1,col2,junk
edit junk.ld
•junk[DimSize(junk, 0)] = {{1},{2}}
•junk[DimSize(junk, 0)] = {{1},{2}}

After the edit command, I had a table showing a 2D wave with no rows, and dimension labels on the columns. At the end, the wave had two rows, with each row having 1 in column 0 and 2 in column 1.

Hi,

make/O)/N=(0,2) junk doesn't work it gives a single dimension wave

Wave: junk
Type: Single Float 32 bit
Rows: 0  Start: 0  Delta: 1  Units: 
Data Units: 
Dimension Labels: No
Size: 648 bytes
Note:

 

Executing this:

make/O/N=(0,2) junk
setdimlabel 1,0,col1,junk
setdimlabel 1,1,col2,junk
edit junk.ld

Yields this:

Wave: junk
Type: Single Float 32 bit
Rows: 0  Start: 0  Delta: 1  Units: 
Data Units: 
Dimension Labels: Yes (Columns)
Size: 1416 bytes
Note:

Andy

Ah, I see the source of the confusion- it's the table and Data Browser treatment that hides the extra dimension info. Usually, if you want to know the dimensionality of a wave, you start at the rows looking for a dimension with zero elements. Clearly, the table and Data Browser work that way, and just about all of Igor worked that way until a few years ago. But it was pointed out that it was useful to be able to create a wave with zero rows and non-zero higher dimensions so that InsertPoints would expand nicely when adding rows. This is particularly useful for a list wave where the dimension labels make column titles and you want to write code that creates the wave, creates the listbox and then inserts rows in response to some event.

If you execute the assignment that was part of my original answer, the columns pop into view. They also appear if you edit the insertion cell to put a single data point in the deceptively one-dimensional wave. Also:

make/O/N=(0,2) junk
print wavedims(junk)
  2
print numpnts(junk)
  0
make/O/N=(0,2,3) junk
print wavedims(junk)
  3
print numpnts(junk)
  0

So you see that Igor is kind of schizoid about wave dimensionality in this case. Conceivably we could modify the way that Igor does this, but given the history of this schizoidness (schizoidity?) I suspect it would take us years to find and alter all the places where this would need to be changed. The behavior I illustrate here was added to Igor specifically for that one use-case, and that explains the inconsistency. My apologies.

Thank you.

Well at least this particular instance proves that I am not crazy.  We'll have to keep trying on that front.

Andy

Something that has caught me more than once is that multidimensional waves revert to 1D if you delete the last row.

If you're maintaining listbox waves with dimension labels used as column headers or for color layers, if there's a chance that the wave is reduced to zero rows you need to redimension and set dim labels again.

Sounds like we handled the creation end of that case, but didn't think about the removal end. Please send a message to support@wavemetrics.com and I'll enter an enhancement request. Probably the engineer that will take care of that will be me...