Plot and append

I have a 2D wave (y_2D) where rows are scaled according to the calculated x-values and the different columns are for different data sets (all with the same x-scaling), and I like to plot each column against the same x-scale in the same plot... I'm having some problems getting this to work - this is what I have:

make/o/n = (num_rows) y_1D
setscale/p x, min, max, "x", y_1D
Display y_1D
for (aa = 0; aa < num_cols; aa += 1)
    y_1D[] = y_2D[p][aa]
    appendtograph y_1D
endfor


I am pretty sure it is something to do with the way the loop is written, but cannot quite figure out how this should be done?
Edited to add: what I am getting now is just many stacked plots of y-1D when aa = num_cols (final column)..
try this:

function plot2Dwave(w)
    wave w // contains traces to be plotted in columns
   
    variable i
    variable nCols = DimSize(w,1)
    Display
    for (i=0; i<nCols; i+=1)
             appendtograph w[][i]
    endfor
end
ChrLie wrote:
try this:

function plot2Dwave(w)
    wave w // contains traces to be plotted in columns
   
    variable i
    variable nCols = DimSize(w,1)
    Display
    for (i=0; i<nCols; i+=1)
             appendtograph w[][i]
    endfor
end



That works - thank you so much!!!

If it isn't too complicated/too much of a trouble, do you mind explaining why my code above is illogical/doesn't work, please?
for (aa = 0; aa < num_cols; aa += 1)
    y_1D[] = y_2D[p][aa]
    appendtograph y_1D
endfor


this overwrites y_1D each time the loop runs. You should end up with num_col traces on the graph which are all on top of each other and have the values of the last column of your 2D wave.