0

嗨,我对使用 Igor Pro 还是很陌生。我正在寻找有关编写任务程序的帮助。

我有 4 个波浪,两个是文本波浪,两个是数字波浪(其中一个还没有数据)。我需要编写一个函数来比较两个文本波,如果它们相等,让 igor 从其中一个数字波中提取数据并将其放在正确的点以匹配与之耦合的文本波。

使其在视觉上概念化

twave1                           twave2

nwave1                           nwave2

twave1 是直到镎的所有同位素列表,但它们不是按顺序排列的,nwave1 是它们对应的质量值。(都在表1上)

twave2 是相同的同位素列表,但排序正确(即 1H、2H、3H、4H...3He、4He...ect)并且 nwave2 为空(均在 table2 上)

所以目标是创建一个函数,对 twave1 和 twave2 进行排序,如果它们匹配,则将 nwave1 中的数据拉入 nwave2,以便质量与 table2 上的正确同位素匹配。所以 table2 将有正确排序的同位素,现在还有质量数据,在正确的位置。

任何帮助将不胜感激; 这是我到目前为止的地方

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
4

2 回答 2

0

如果我理解正确,最后你想要的两个波是isotopeME。您的代码接近工作,但是当您声明一个文本波时,您需要使用 /t 标志告诉 Igor 它是一个文本波。我进一步简化了代码:

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

此代码不是很健壮,但适用于您想做的事情。

要测试代码,这是我的 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()
于 2020-05-30T05:17:05.597 回答
0

我认为stringmatch这里不是正确的选择。它使用通配符匹配,但 OP AFAIU 想要匹配/不匹配,因此!cmpstr是更好的选择。

于 2020-06-01T11:26:25.080 回答