same string and wave name in function

nicha
Posts: 5
Joined: 2010-08-31
Location: United States

Function diurnal_hr()
variable i
wave d_int
string word = "diurnal_"
for(i=0;i<24;i+=1)
string di = word + num2str(i)
Make/ N = 974 $di
$di = d_int[p*24+i]
endfor
End

This is my function. I tried to separate the wave d_int into 24 waves. However, the wave name is in form of string. So when i compile, the 8th line, "$di = d_int[p*24+i]", was error.

Thanks so much


awirsing
Posts: 130
Joined: 2007-09-19
Location: Germany

nicha wrote:
However, the wave name is in form of string. So when i compile, the 8th line, "$di = d_int[p*24+i]", was error.

You have to use a wave reference here:

Function diurnal_hr()
	variable i
	wave d_int
	string word = "diurnal_"
	for(i=0;i<24;i+=1)
		string di = word + num2str(i)
		Make/N = 974 $di
		wave ww = $di
		ww = d_int[p*24+i]
	endfor
End

A.


nicha
Posts: 5
Joined: 2010-08-31
Location: United States

thanks :)


Posts: 566
Joined: 2007-06-29
Location: United States

And if you're using 6.12 or later (I think that's when this feature was added) you can combine the WAVE declaration with the Make command:

Function diurnal_hr()
	variable i
	wave d_int
	string word = "diurnal_"
	for(i=0;i<24;i+=1)
		string di = word + num2str(i)
		Make/N = 974 $di/WAVE=ww
		ww = d_int[p*24+i]
	endfor
End

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com


Back to top