display updating old plots

 	make/o/n = (numbpoints) voltvsfreq =0                       //each i corresponds to frequency val
	SetScale x, 0, numbpoints, voltvsfreq
	display /K=1 voltvsfreq as num2str(initialfreq)
	
	wait(.4)
	
	variable frequency  = initialfreq
 	do
 		voltvsfreq[i] = magaverage(id, wavechannel,  frequency, acq_time, sample_rate)
	
 		freq(wavechannel, initialfreq+i*interval)

 	while (i<numbpoints)

I have to run the block of code above multiple times and I noticed that it keeps updating my old plots.

Each time I run the code above generates a new plot but the old plot gets updated simultaneously, resulting in the old plot being a duplicate of the new plot.

I haven't been able to figure out how to keep the old plots intact while generating a new plot. 

 

Hi,

The code make a new graph every time it is run via the display operation. The graph is always using the same wave, voltsvsfreq, in every graph so you are in essence just replotting the same wave with a new title string in the display window. If you want to keep a specific graph and the displayed intact, you will need to duplicate the wave voltsvsfreq to some unique name. 

 

Andy

In other words: To store new data while keeping the old one you have to make a new wave. The display and the data itself is independent, so you are updating the data and all your graphs reflect that since the same data is displayed in all graphs.

To create a new wave with an unique name (by attaching a number to the wave name) you can, for example, use the 'UniqueName' function like this:

String DataName = UniqueName("voltvsfreq", 1, 0)     // string with unique (numbered) name
Make/o/n = (numbpoints) $DataName =0                 // create wave for current data instance
Wave currentdata = $DataName                         // reference to current data wave

SetScale x, 0, numbpoints, currentdata
Display /K=1 currentdata as num2str(initialfreq)
   
wait(.4)
   
variable frequency  = initialfreq
do
   currentdata[i] = magaverage(id, wavechannel,  frequency, acq_time, sample_rate)
   freq(wavechannel, initialfreq+i*interval)
while (i<numbpoints)