DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

How to calculate absolute value of channel in python script?

Solved!
Go to solution

I want to calculate the absolute value of an channel and save the result in another channel.

But this code as described in the documentation does not work:

 

dd.Calculate("Ch(""Group3/Result"")= Abs(Ch(""Group1/Input""))") 

 

 But the same code works as .VBS Script:

 

Call Calculate("Ch(""Group3/Result"")= Abs(Ch(""Group1/Input""))")

 

 How can I achieve the same behaviour in Python?

 

Thanks for your help!

0 Kudos
Message 1 of 5
(216 Views)
Solution
Accepted by topic author blume

Hi blume,

 

The problem is the double quotation marks

 

This here will work:

dd.ChnCalculate('Ch("Group1/Result")= Abs(Ch("Group1/Input"))') 

 

Greetings

Walter

Message 2 of 5
(176 Views)

Thank you very much!

0 Kudos
Message 3 of 5
(167 Views)

Is it possible to do this calculation in a for loop?

For example:

 

for j in range(2, 5):
    dd.ChnCalculate('Ch("Group1/Result")= Abs(Ch("[1]/[j]"))')

Greetings

blume

0 Kudos
Message 4 of 5
(134 Views)

You can try this:

 

for j in range(1, 5):
    dd.ChnCalculate('Ch("Group1/Result' + dd.str(j) + '")= Abs(Ch("[1]/[' + dd.str(j) + ']"))')

Greetings

Walter

Message 5 of 5
(122 Views)