DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Divide a channel by a number?

Probably an easy task but I need help to solve this for DIAdem 2021.

I want use a selected channel from the data portal and divide that channel by 1000.

Since "portal.Structure.Selection.Item(1)" returns "[1]/Time" I cannot get the Calculate-function to work.

I have tried with "", with """" and with other variables but it only seems to work when typing "[1]/Time" instead of T3.

Is there any solution to the code below?

 

T3 = portal.Structure.Selection.Item(1)

Call Calculate(Ch(T3)=Ch(T3)*1000)

 

Many thanks in advance

0 Kudos
Message 1 of 5
(2,783 Views)

Have you tried using a "formula channel"? If you right click in the data portal in the same group as the channel you want to use for your function, you should see "new -> Formula Channel", then you can set the channel name (default is "Result"), and drag and drop your channel you want to use (maybe it is "Speed"), and set the formula up like you want.  If your channel is named "Speed", your formula would be Speed/1000.  If you want this in a script call, just record a script before you run the above commands!

0 Kudos
Message 2 of 5
(2,767 Views)

Hi @Mike_77, 

 

you can use the following syntax for doing that: 

 

Call Calculate("ch(""[1]/[1]"") = ch(""[1]/[1]"")/1000") 

 

Just replace the information for the channels with the names you want to use. 

0 Kudos
Message 3 of 5
(2,725 Views)

Formula Channel works. But perhaps "Scale" is easier and faster.

 

From GUI:

Analysis -> Basic -> Scale.

Set offset = 0, gain = 1/1000

 

Immagine.png

 

 

If you need to do it programmatically:

 

Script Python:

 

 

#------------ Command -------------------
dd.ChnResult = dd.ChnLinScale("YourGroup/InputChannel", "YourGroup/OutputChannel", 0.001, 0)

 

 

 

Script VBA

 

 

'------------ Command -------------------
Set ChnResult = ChnLinScale("YourGroup/InputChannel", "YourGroup/OutputChannel", 0.001, 0)

 

 

 

 

 

0 Kudos
Message 4 of 5
(2,718 Views)

Sorry for not being clear in my question but it is not the division calculation that is the issue here.

It is how to use, either "portal.Structure.Selection.Item(1) = portal.Structure.Selection.Item(1)/1000" or to use a string variable like T3 so

T3 = portal.Structure.Selection.Item(1)                'This gives us T3 = [1]/Time

T3 = T3/1000

I need to divide or multiply a selected channel by 1000.

 

And yes, the "Scale" solution would work but since it is a Time channel that I want to divide, the scaling function is not exactly dividing by 1000, it somehow rounds or adds decimal values so if scaled up by 1000 again we don't end up with the same value as from the start...

 

Any solution proposals?

 

0 Kudos
Message 5 of 5
(2,698 Views)