0

Hi I'm pretty new to using Igor Pro. I'm looking for some help on writing a procedure for a task.

I have 4 waves, two are text waves and two are numeric waves(one of which has no data yet). I need to write a function that will compare the two text waves and if they are equal, have igor pull data from one of the numeric waves and put it in the correct point to match the text wave it's coupled with.

To make it visually conceptually

twave1                           twave2

nwave1                           nwave2

twave1 is a list of all isotopes up to neptunium but they're not in order, and nwave1 is their corresponding mass values. (both on table1)

twave2 is the same list of isotopes but ordered properly (i.e. 1H, 2H, 3H, 4H...3He, 4He...ect) and nwave2 is empty (both on table2)

so the goal is to create a function that will sort through twave1 and twave2, and if they match, pull the data from nwave1 into nwave2, so that the masses match with the correct isotopes on table2. So table2 will have the correctly ordered isotopes and now the mass data as well, in the correct places.

Any help would be greatly appreciated; this is where I've gotten so far

function assignMEf()
    wave ME, ME_FRIB
    wave isotope_FRIB, isotope
    variable len = numpnts(ME)
    variable i, j
    variable ME_current, iso_current

    for(i=0; i<len; i+=1)
     ME_current = ME[i]
     iso_current = isotope[i]
   for(j=0; j<4254; j+=1)
    if(iso_current == isotope_frib[j])
        ME_frib = ME[i]
    endif
   endfor
  endfor

end
Ardent Coder
  • 3,777
  • 9
  • 27
  • 53

2 Answers2

0

If I understood correctly, the two waves you want at the end are isotope and ME. Your code was close to working, however you need to tell Igor when you declare a text wave that it is a text wave, by using the /t flag. I simplified the code a bit more:

function assignMEf()
    wave ME, ME_FRIB
    wave/t isotope, isotope_FRIB
    variable len = numpnts(ME)

    variable i, j

    for(i = 0; i < len; i += 1)
        for(j = 0; j < len; j += 1)
            if(stringmatch(isotope[i],isotope_frib[j]))
                ME[i] = ME_FRIB[j]
            endif
        endfor
    endfor
end

This code is not very robust but works for what you'd like to do.

To test the code, here is my MWE:

•Make/O/N=(10) ME_FRIB = p
•Make/O/N=(10) ME = NaN
•Make/O/N=(10)/T isotope_FRIB = "iso" + num2str(10 - p)
•Duplicate/O isotope_FRIB,isotope
•Sort isotope,isotope
•Edit isotope_FRIB,ME_FRIB,isotope,ME
•assignmef()
quantixed
  • 287
  • 3
  • 12
  • Hi! Thank you so much for your help, it's exactly what I needed except the end waves are going to be Isotope_Frib and ME_Frib. If I understand correctly, I should be able to switch the wave names around in the function and it'll work exactly how I intend? – Dakota Keblbeck May 30 '20 at 15:28
  • OK. Yes. The only switch you need to make is `if(stringmatch(isotope_frib[i],isotope[j]))` and `ME_FRIB[i] = ME[j]` I haven't tested that, but I think it's right. Glad to help, if this answer solved your problem please mark it as accepted by clicking the check mark next to the answer. – quantixed May 30 '20 at 16:27
0

I don't think stringmatch is the right choice here. It uses wildcard matching but the OP AFAIU wants match/no-match so !cmpstr is a better choice.

t-b
  • 152
  • 1
  • 7