Automatically demote wave duplication outputs when the highest dimension has one index

I often run into trouble when I don't realize that a 1-column 2D wave is not a 1D wave. Usually, these result after I run duplicate/o/r=[][columnOfInterest] sourceWv,columnWave and forget to follow it with redimension/n=(-1) columnWv

I think it would be better if duplicate's default was to demote the wave (i.e., to 1D in this case) if possible.

Would it be possible to use the following syntax to get either behavior in some future version of Igor?

duplicate/o/r=[][2] sourceWv,columnWv
print dimsize(columnWv,1)        //currently prints one. In the future, let the duplicate result in 0, indicating 1D wave
duplicate/o/r=[][2,2] sourceWv,columnWv
print dimsize(columnWv,1)        //current also prints one. In the future, this behavior should be unchanged

The advantage of this change in syntax would be that the simpler syntax produces the more intuitive result (in my opinion). I suppose the main danger is that someone accidentally erases the dimension label for the duplicated column (or layer, etc.) 

For backwards compatibility and transparency, perhaps instead duplicate could just have a flag (e.g., /dem) to demote if the highest dimension if the output wave has only one index.

I'm all for that. And of course it should work for columns, layers, chunks. And I also prefer a new flag so that existing code still works.

Could the new flag /DIM=N also upsize? Would that be of any use?

duplicate/r=[][2]/DIM=0 sourceMatrix, columnWave
// make a new matrix filled with the second column of an existing matrix
duplicate/r=[][2]/DIM=2 sourceMatrix, newMatrix

 

Just curious, have you considered using:

MatrixOP/O columnWv = col(sourceWv,2)

The result is 1D, however wave scaling would not be preserved.

If columnWv pre-exists and has been scaled,

/S      Preserves the dimension scaling, units and wave note of a pre-existing destination wave in a MatrixOp/O command.

 

In reply to by thomas_braun

Thomas, I agree with what you would want. However, the help file must be read literally.

In the following example snippet

function doit()
    make/O/N=(10,5) sourceWv
    setscale x, 1,4,"", sourceWv
    setscale y, 2,3,"", sourceWv
    sourceWv = x+y
    make/O/N=10 columnWv
    copyscales sourceWv, columnWv
    MatrixOP/O/S columnWv = col(sourceWv,2)
end

you get the desired result. However, if MatrixOP has to create the new columnWv, the sourceWv scaling does not transfer.

In reply to by ChrLie

ChrLie wrote:

Just curious, have you considered using:

MatrixOP/O columnWv = col(sourceWv,2)

The result is 1D, however wave scaling would not be preserved.

I have, but I usually want to preserve wave scaling, labels in other dimensions, and/or the wave note.

I am not looking for alternatives. In posting, I just wanted to point out that the current Duplicate behavior is sometimes troublesome/confusing, so some explicit handling (via a flag or syntax) would be an improvement.

 

jjweimer wrote:

Could the new flag /DIM=N also upsize? Would that be of any use?

Seems to me like it could be helpful, but it's hard for me to say what rules should be followed for any new points (and how they would generalize up to 4 dimensions).

 

Thanks!