简体   繁体   中英

Igor Pro 8, functions for comparing strings

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 (ie 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

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()

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM