How to remove/avoid x-scaling

Last question for today. I am doing the following:

make wave_1 setscale/i x, (low), (high), wave_1 wave_1 = (some function) -manually recreate the x scaling to use in an axis transform make x_scale_1 = low + (high-low)*P/(total_points-1) -do the transform, which inverses the direction among other things make x_scale_2 = x_scale_1* (-1) * (other things) -copy the original wave just to separate things if needed later make wave_2 = wave_1 -reverse both waves as I want to graph them in the correct order and I notice that even tho it looks right, it screws up the integrate function if I dont reverse wave_2 reverse x_scale_2 -graph it display wave_2 vs x_scale_2 -integrate to get a cumulative trace integrate/meth=1 wave_2 /x=x_scale_2 /d = output_wave variable maxval = output_wave[last_point] output_wave /= maxval/100 appendtograph output_wave vs x_scale_2

that last line i found very strange that I MUST tell it to do vs x_scale_2, as otherwise it graphs backwards despite being told to integrate in the first place according to x_scale_2
more wierdness is that my output_wave is a Hill curve (sigmoid looking) that starts at 0 and swings up to a base line at 100, but if I type
print output_wave(x) with large values of x, it returns zero, and small values return 100. which is backwards.

What am I doing wrong, why is it remembering this directional behavior? I have appended the waves to a table to inspect them before graphing or integrating, and they run in the correct direction as far as min and max values and point order.
Here is the original code if that is more useful
#pragma rtGlobals=1     // Use modern global access method.
function lntest(median,DI)
variable median,DI
DI = DI/100
variable sigma = sqrt(ln(DI^2+1))
variable mean_x = ln(median) //+ sigma^2  //comment in sigma and the median becomes the mode
string y1_name = "PS_" + num2str(median)
string y2_name = "Ca_" + num2str(median)
string x1_name = y1_name + "_x"
string x2_name = y2_name + "_x"
string c_name = "cumu_" + num2str(median)

make/o/d/n=1000 $y1_name
wave main1 = $y1_name
setscale/i x, 0.1*median,5*median, main1
main1 = 1000*(1/(x*sigma*sqrt(2*pi))) * exp((-1/(2*sigma^2))*(ln(x)-mean_x)^2)
wavestats/q main1
main1 /= V_max/100

make/o/d/n=1000 $x1_name
wave main1_x = $x1_name
main1_x = 0.1*median + 4.9*median*p/999

make/o/d/n=1000 $y2_name
wave main2 = $y2_name
main2 = main1
reverse main2

make/o/d/n=1000 $x2_name
wave main2_x = $x2_name
main2_x = 3516.5 * main1_x ^(-1.2159)
reverse main2_x

//edit
appendtotable main1,main1_x,main2,main2_x
DoWindow /F graph_main   // /F means 'bring to front if it exists'
print "V_flag is", V_flag
if (V_flag == 0)
    // window does not exist
    Display /N=graph_main main2 vs main2_x // note '/N=' flag
else
    Dowindow /K graph_main
    Display/N=graph_main  main2 vs main2_x
endif



integrate/meth=1 main2 /x = main2_x /d = $c_name
wave cumu = $c_name
variable full_area = cumu[999]
cumu /= full_area/100
appendtotable cumu
appendtograph cumu vs main2_x

ModifyGraph rgb($c_name)=(0,0,0)
ModifyGraph/w=graph_main rgb($y2_name)=(0,0,0)
CurveFit/X=1/NTHR=0/TBOX=768 HillEquation  cumu /X=main2_x /D

end

-integrate to get a cumulative trace

integrate/meth=1 wave_2 /x=x_scale_2 /d = output_wave
variable maxval = output_wave[last_point]
output_wave /= maxval/100

appendtograph output_wave vs x_scale_2

that last line i found very strange that I MUST tell it to do vs x_scale_2, as otherwise it graphs backwards despite being told to integrate in the first place according to x_scale_2

For this particular point of confusion, I think the answer is if you supply an X-wave to the integrate command, the assumption is you'll want to plot the cumulative area function vs that same x wave. It sounds like you're assuming the Integrate operation will set x-scale of the cumulative wave to match the supplied X-wave, but that's not what it's doing (I suppose it could with an extra interpolation step, but not everyone would want/assume that behavior, as the output would no longer display correctly vs. the X-wave that was used). It's just copying the X-scale of the Y-data wave, even if an X-wave was supplied. You may also have missed that your integration produced negative valued results, because you fix that when you rescale the cumulative data. Whether it's XY data or waveform data, the integrate operation returns the integral from the 0th point (not necessarily the minimum X value) and going to the nth point, so that positive valued Y-data stored in reverse X order will give you negative results in the cumulative integration.

It's also worth noting that when you do
make wave2
wave2 = wave1  

it's different from
duplicate wave1, wave2

in that the scaling is NOT copied in the first example, although I'm not really sure that's the issue here.

As more a more general comment...I'm getting confused following your code, and I think you could probably get by without using so the reverses. Integrate and Display can both be used to do what you want regardless of the order of the underlying data, and at worst you can multiply the cumulative integration by -1 (or subtract it from the last point value) because you're really interested in the "area under the curve" as opposed to a directionally dependent signed integration (which is the negative of the area if the integration is from high X to low X). I think every Igor function/operation that requires monotonic X-values is okay with monotonically decreasing X-values.)

Also as a side comment...I'm a big fan of plotting a second set of data on the right axis in order to visualize two data sets with different numerical magnitudes, simply because it's fast and easy to do, and doesn't require rescaling the data. If the absolute value of the integration rather than just its general shape is meaningful, you can read the numbers on the right axis ticks but still see both curves because the axes autoscale independently. More of a personal preference than a clearly superior method, but worth considering if it hadn't occurred to you. It can also be scaled up to many waves if each is plotted on it's own new vertical axis, but that takes more tweaking to clean up overlapping ticks and labels.
Thanks for the response, very much.

I used the wave1 = wave2 command instead of duplicate, specifically because I had hoped it didnt copy x-scaling, so that is relieving to hear.
Its embarassing, but I think all my trouble stemmed from thinking of integrals simply as areas under the curve, and forgetting about the effect the x-points can have on the sign. Silly, but it has been ages and ages since calculus. Thanks for reminding me. I could have sworn I had done things correctly regardless, but Im sure there must be a related mistake in there somewhere. Its nice to know its not persistant x-scaling but instead a simple oversight.

Thanks again, and merry christmas. =)
If I graph the output ca_(number) files from this program (they are transformed log normal distributions), everything looks nice.

I want to add a few of them together with respect to x, but I am having a really hard time as I cant use this command

wave_sum = wave_1(x) + wave_2(x) etc...

unless the waves have x scaling, but i cant get x scaling into these output waves as the points are non-linearly spaced. That is, the x values in the ca_(number)_x wave have a variable delta between them.

What can I do? This seems way more effort than it need be =(
daggaz wrote:
so I do the following:
wavestats wave_x
setscale/i x,V_min,V_max, wave_y
display wave_y

and now it graphs it backwards when compared to the orginal graph of

display wave_y vs wave_x

Yes- Reverse works as advertised :)

V_min and V_max will always have the order V_min < V_max so your SetScale operation should result in positive deltaX. Are you absolutely certain that you are looking at the correct wave in your table? Is it at all possible that the X values are negative and what you are seeing is actually that the smallest magnitude is at the top of the table? That would result in a decreasing X order as the "larger" values would actually be more negative.

The only other thing I can think of is that somewhere else in your code you are reversing something after you set up the X wave.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
johnweeks wrote:


The only other thing I can think of is that somewhere else in your code you are reversing something after you set up the X wave.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com


sorry John, I figured out what I was doing wrong and went back and changed the question. Didnt think you guys would be so hot on the ball, but thanks =)

(it was because my x_wave is non-linearly spaced.)

EDIT
....and I figured out a bandaid. My transforms are themselves still log-normal (not sure why but not going to complain). I just refit them and use the fits instead, have new waves with xscaling that match the old ones. Ugh my head.