Filling wave in for loop

Hi,

I am filling the waves (for which I don't know in advance the name of wave) in for loops. Because I am the beginner in Igor programming I have problems. The problem is that I have two for loops where in first for loop I create waves and then filling them with values in the second one. Here is the code:

Function FinalDataSet()
        Make/O/T ionic = {"15","30","50","75","100","175"}
        Make/O/N=(8) pH =p+3
        Variable i, j
        For (i=0; i<6;i+=1)
            Make/O/N=(8) $("KD_I" + ionic[i])
            Wave tmpKDI= $("KD_I" + ionic[i])
       
            Print tmpKDI
           
            For (j=0;j<8;j+=1)
            Wave wInputDLS = $("coef_"+"pH" + num2str(pH[j]) + "I" + ionic[i]+"_DLS_clean")
            Print wInputDLS[1]
           
            tmpKDI[j]=wInputDLS[1]
             endfor
        endfor
End    


When I print the reference waves in the code above I get strange values in the resulting wave assigned in tmpKDI.

Any help is appreciated!

Thanks,
Dejan
It's difficult to understand your function without knowing what your data represents and what the function is trying to achieve but here are some comments.

I don't see any obvious errors in the function.

Here is a reworked version of your function. The comments explain the changes I made or contain observations I made.

Function FinalDataSet2()
    Make/O/T ionic = {"15","30","50","75","100","175"}
    Make/O/N=(8) pH = p+3
    Variable i, j
    For (i=0; i<6; i+=1)
        String kdName = "KD_I" + ionic[i]   // Store name in temporary string variable
        Print kdName                        // to make it easier to debug
        Make/O/N=(8) $kdName            // and to avoid repeating the same expression.
        Wave tmpKDI= $kdName
 
        // At this point tmpKDI points to a wave that you just made above. It should contain all zeros.
        // It seems like it would make more sense to be printing tmpKDI after the next for loop.
        Print tmpKDI
 
        For (j=0;j<8;j+=1)
            String wInputDLSName = "coef_"+"pH" + num2str(pH[j]) + "I" + ionic[i]+"_DLS_clean"
            Print wInputDLSName         // Store name in temporary string variable . . .
            Wave wInputDLS = $wInputDLSName
            Print wInputDLS[1]
 
            tmpKDI[j]=wInputDLS[1]
        endfor

        // It seems like it would make more sense to be printing tmpKDI here, after you have stored values in it.
        Print tmpKDI
    endfor
End


If my comments and suggestions don't help, I recommend that you try the Igor debugger. Execute this for help:
DisplayHelpTopic "The Debugger"

hrodstein wrote:
It's difficult to understand your function without knowing what your data represents and what the function is trying to achieve

Thanks, it works. It seems that I messed something with temporarely strings.
Sorry for sending code without comments.

Dejan