Simple Plot routine ( ywave vs x wave) from Table does not work on the Fitted ( fit_wave1.d vs fit_wave1.x ) data set

This code plot ywave vs xwave from a table (mark/select the wave/data sets in the table by mouse and then click "Plot XY" menu)
But whenever I fit a data set (that I can plot by PlotXY procedure) to a Gaussian and then tried to plot the fitted wave set (fit_wave1.d and fit_wave1.x) the PlotXY code does not work..its give a error " expected wave name"..
Can anybody tell me how to solve this.

#pragma rtGlobals=1     // Use modern global access method.

Menu "Plot XY"
      "Simple Plot Select XY Pair A/1", SimplePlot(0)
End

Function SimplePlot(AorB)

Variable AorB        // 0 for A, 1 for B
     
      String tableName = WinName(0, 2,1)
      if (strlen(tableName) == 0)
              Abort  "There are no tabels"
      endif

GetSelection table, $tableName, 1      //Get selection row and column indices
       Variable startColumn = V_startCol               //Index of first selected column - assumed to be x wave

       //First selected column is assumed to be x1
       Wave x1 = WaveRefindexed(tableName, startColumn, 1)

   
       //Second column after first selected column is assumed to be y2
       Wave y2 = WaveRefindexed(tableName, startColumn+1, 1)

Display y2 vs x1

     End
Simple Plot.pxp (42.02 KB)
The fitted result is not an XY Pair of waves; it is one wave with the x part as "wave scaling".

--Jim Prouty
Software Engineer, WaveMetrics, Inc.
Hi Jim..Thanks
How can I generate two wave ( wave0, wave 1) from this this single wave with two column ...and then can use the same plot routine...ort may there is some other way ?
You'd need to check the column name for ending with ".x" and not try to plot that column; just plot the other column using "Display y2".

--Jim Prouty
Software Engineer, WaveMetrics, Inc.
So if I try to plot by " Display fit_wave1 " then it works....but

1. How I extract column name "fit_wave1" from the wave data " fit_wave1.d" ?

the command " Wave y2 = WaveRefindexed(tableName, startColumn+1, 1) " does define a wave ..but the fit_wave1.d is already defined as wave..

Somehow I dont fully understand how to extract column name from 1D waveform with data and scaling attached...--. d ---. x )
You could make a new wave and then insert the scaling of fit_wave1 to have a separate x wave. Like so (this wave has to be of course of the same size as the fit-wave): fit_wave1_x = DimOffset(fit_wave1,0) + p*DimDelta(fit_wave1,0)

But why would you want to do that? I'd suggest you modify the code to accept scaled 1D-waves, since this is the normal way for data in Igor. Actually, I would try to bring the original data in this format to avoid a lot of hassle (assuming the x wave is evenly spaced, and even if not you could always go for interpolate), but thats maybe personal preference. But anyway, in the current state the code is very prone to errors since its assuming a lot (wave has to be XY, data was selected in the right order, x and y data directly adjacent, etc.). You could use more of the information which GetSelection provides, at least V_endcol. This way, it would also be very easy to check for scaled data and have just Display y1 instead.
Thanks Chozo ... extremely sorry for writing so late...just took me some time to come back and again started coding in Igor...indeed you are right...I should change the code...but for time being I used display command for plotting of wave data ...I changed it to

String x1Name = NameOfWave(x1)
Display x1
Display y2 vs x1


I kept both
Display x1
Display y2 vs x1

so it works for both on XY and and also on wave...although on wave it does gives a error for Display y2 vs x1 command as it doesn’t find wave...
Its a kind of crude way ...but at least it works on both situation.

I don’t know how I can distinguish programmatically between XY ( individual wave) and waveform data and then can use either Display y2 vs x1 or Display x1..so I used both
Hi Supra,
With your current code, you could use WaveExists to check if there is a second wave. Like so:
if (WaveExists(y2))
    Display x1 vs y2
else
    Display x1
endif

But it would also be possible to see if a second wave was selected in the first place:
GetSelection table, $tableName, 1
if (V_startCol == V_endCol)     // look if only one col is selected
    // process one wave
    Wave x1 = WaveRefindexed(tableName, V_startCol, 1)
    Display x1
else
    // process two waves
    Wave x1 = WaveRefindexed(tableName, V_startCol, 1)
    Wave y2 = WaveRefindexed(tableName, V_endCol, 1) // use end col directly
    // this way they don't need to be adjacent
    // you still would need to have them in the right order
    Display y2 vs x1
endif

Hope this helps. There are more ways to get the information needed to distinguish cases. You may have your reasons to work with tables. But if it's only for the sake of selecting waves, it would be possible/much easier to skip this step and directly read selected waves from the data browser and work with them.
Thank you so much Chozo ...."WaveExists" worked perfectly...thanks a lot.