How to select one of 24 numbered waves: wave0, wave1.....wave23
hans.frank
After loading a JCAMP.dx file I get 24 waves numbered wave0, wave1......wave23.
I want to calculate the difference between 2 of such sets using a loop but I don't see how to select each wave.
A good way to organize your data sets is to load each dataset (wave0..wave23) into a separate data folder. If you are not familiar with data folders, execute:
DisplayHelpTopic "Data Folders"
The way to address waves in a loop is to use the $ operator to create a wave reference from a string containing a wave name. If you are not familiar with wave references, execute:
DisplayHelpTopic "Wave References"
and
DisplayHelpTopic "Accessing Global Variables And Waves"
Here is an example that creates two datasets, each in its own data folder, and then creates a third data folder containing difference waves:
String name
int i
// Make n demo waves in data folder dfA
NewDataFolder/O/S dfA
for(i=0; i<n; i+=1)
sprintf name, "wave%d", i
Make/O $name = i + p
endfor
SetDataFolder ::
// Make n demo waves in data folder dfB
NewDataFolder/O/S dfB
for(i=0; i<n; i+=1)
sprintf name, "wave%d", i
Make/O $name = i + p
endfor
SetDataFolder ::
End
// Example:
// MakeDemoWaves(3)
// DemoDifWaves(3, dfA, dfB)
Function DemoDifWaves(int n, DFREF dfA, DFREF dfB)
String name
int i
NewDataFolder/O dfDif
DFREF dfDif = :dfDif
// Create difference waves in current data folder
for(i=0; i<n; i+=1)
sprintf name, "wave%d", i
WAVE aWave = dfA:$name
WAVE bWave = dfA:$name
String difName
sprintf difName, "difAB_%d", i
Duplicate/O aWave, dfDif:$difName
WAVE difWave = dfDif:$difName
difWave = bWave - aWave
endfor
End
August 29, 2023 at 08:34 am - Permalink
In reply to A good way to organize your… by hrodstein
Thanks a lot for this demo, After getting familiarised with datafolders I successfully could solve my problem using this template.
September 1, 2023 at 09:56 am - Permalink