Dividing all waves in a folder by a value
mespri
Hi guys,
I have a problem, which might be very easy to solve. I have a folder with waves and I want to divide all waves by the factor 1000 using the following function:
Function NormalizeAll() Variable n=ItemsInList(wavelist("*",";","")) Variable i For (i=0; i<=n; i+=1) $(StringfromList(i,wavelist("*",";","")))=$(StringfromList(i,wavelist("*",";","")))/1000 EndFor End
The error is: "Can't use $ in this way in a function". I am confused, because I have used the $-trick in a function before. If I put the line in the for loop in the commander for a specific value of i, it works. Thank you for your help!
You have to declare the wave first
Variable n=ItemsInList(wavelist("*",";",""))
Variable i
For (i=0; i<=n; i+=1)
Wave MyWave=$(StringfromList(i,wavelist("*",";","")))
MyWave=MyWave/1000
EndFor
End
December 15, 2022 at 06:36 am - Permalink
Thank you <3
December 15, 2022 at 06:47 am - Permalink
For your curiosity here is another way of accomplishing the same thing with different commands
// The datafolder to look for waves in
DFREF MyFolder=root:MyFolder
// Checks that the datafolder exists
If ((DataFolderRefStatus(MyFolder)!=0)
// Counts the number of waves in the folder
// (If you have non-numeric waves in the folder you will have to add additional checks for that)
Variable n=CountObjectsDFR(MyFolder, 1)
// Creates a list of all waves in the folder
Make/FREE/O/WAVE/N=(n) AllWaves=WaveRefIndexedDFR(MyFolder, p)
// Multithreads dividing the waves by 1000
MultiThread AllWaves[]=DoStuffToWave(AllWaves[p])
endif
end
ThreadSafe Function/WAVE DoStuffToWave(MyWave)
// Divides the waves by 1000. Uses FastOP for speed increase
Wave MyWave
FastOP MyWave=(1/1000)*MyWave
Return MyWave
end
December 15, 2022 at 08:35 am - Permalink
Hi,
Depending on how often you need the command, don't forget the ability to execute a command in the data browser.
Select all the waves of interest and then in the execute command dialog:
%s /=1000
Andy
December 15, 2022 at 08:46 am - Permalink
Here's a GUI for normalizing waves
December 16, 2022 at 03:26 am - Permalink