Find x-value corresponding to maximum y-value
Physicist92
Hi all,
I created 5 test waves using the command:
Make '1','2','3','4','5'
'1' = exp(-(p-60)^2/50)
'2' = 2*exp(-(p-50)^2/50)
'3' = 3*exp(-(p-70)^2/50)
'4' = 4*exp(-(p-75)^2/50)
'5' = 5*exp(-(p-39)^2/50)
'1' = exp(-(p-60)^2/50)
'2' = 2*exp(-(p-50)^2/50)
'3' = 3*exp(-(p-70)^2/50)
'4' = 4*exp(-(p-75)^2/50)
'5' = 5*exp(-(p-39)^2/50)
The purpose is to find x-values corresponding to maximum y-value for each wave.
I wrote the following function:
Function find_v0_values()
Make/O/D/N=(5,3) v0_values // Make wave with 5 rows and 3 columns
// 1st column is for names of waves (1,2,3,4,5)
// 2nd column is for maximum y-values
// 3rd column is for x-values corresponding to maximum y-values
String list = WaveList("*",";","")
Variable numItems = ItemsInList(list), ii
String name
Variable extremum, v0
for (ii=0; ii<numItems; ii+=1)
name = StringFromList(ii,list)
Wave w = $name
WaveStats/Q w
extremum = V_max
v0 = V_maxloc
v0_values[ii][0] = str2num(name) // fill wave v0_values
v0_values[ii][1] = extremum
v0_values[ii][2] = v0
endfor
End
Make/O/D/N=(5,3) v0_values // Make wave with 5 rows and 3 columns
// 1st column is for names of waves (1,2,3,4,5)
// 2nd column is for maximum y-values
// 3rd column is for x-values corresponding to maximum y-values
String list = WaveList("*",";","")
Variable numItems = ItemsInList(list), ii
String name
Variable extremum, v0
for (ii=0; ii<numItems; ii+=1)
name = StringFromList(ii,list)
Wave w = $name
WaveStats/Q w
extremum = V_max
v0 = V_maxloc
v0_values[ii][0] = str2num(name) // fill wave v0_values
v0_values[ii][1] = extremum
v0_values[ii][2] = v0
endfor
End
But this function doesn't work properly. Function Execution Error arises. Please find attached the error message and created wave v0_values. The last 5th row in this wave is wrong. How can I solve this problem?
Forum
Support
Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More
I wrote:
instead of
and it worked. But I don't understand, why I should write ii < numItems - 1 instead of ii < numItems ?
April 22, 2019 at 08:27 am - Permalink
Another way to find the x location of a y maximum is to call wavestats. It produces: V_maxloc X location of maximum data value.
Andy
April 22, 2019 at 08:34 am - Permalink
In reply to Another way to find the x… by hegedus
Thanks for reply! Yes, in my function, I use V_maxloc. But the problem is why should I write ii < numItems - 1 instead of ii < numItems ? I thought that if I write:
and given that numItems = 5,
it will result in ii = 0, 1, 2, 3, 4. But it appears that Igor Pro counts in another way: ii = 0, 1, 2, 3, 4, 5, thus including the point 5. How can it be?
April 22, 2019 at 08:39 am - Permalink
One thing to note is that the first thing in the function is to create a new wave so if you have 5 data waves originally you will now have 6 total waves. The wavelist function could be tailored to avoid including that wave. Another strategy is to have separate data folders for input data and analysis waves.
Andy
April 22, 2019 at 09:22 am - Permalink
In reply to One thing to note is that… by hegedus
Thanks a lot! I just changed the order of two first lines in my function:
Make/O/D/N=(23,3) v0_values
And now I can write
for (ii=0; ii<numItems; ii+=1)
April 22, 2019 at 09:32 am - Permalink
In reply to Thanks a lot! I just changed… by Physicist92
This is a good place to put in a plug for the debugger. Using this, you might have discovered that ItemsInList was returning a different value from what you were expecting.
For more info, execute the following from the command line:
April 22, 2019 at 10:16 am - Permalink