# DIAdem

cancel
Showing results for
Search instead for
Did you mean:

Solved!
Go to solution

## How to calculate absolute value of channel in python script?

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!

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

## Re: How to calculate absolute value of channel in python script?

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)

## Re: How to calculate absolute value of channel in python script?

Thank you very much!

Message 3 of 5
(167 Views)

## Re: How to calculate absolute value of channel in python script?

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

Message 4 of 5
(134 Views)

## Re: How to calculate absolute value of channel in python script?

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)