Topic
Division durch Null
Startseite ' Community ' FPScript ' Division durch Null
- Dieses Thema hat 5 Antworten sowie 2 Teilnehmer und wurde zuletzt vor vor 19 Jahren, 2 Monaten von Martin Uellenberg aktualisiert.
-
AutorBeiträge
-
03.03.2006 um 18:24 Uhr #33316Martin UellenbergTeilnehmer
Hallo,
ich möchte die y-Werte von zwei Signalen (Signal1 und Signal2) durcheinander dividieren. Sobald der Wert des Divisors = 0 ist, bekomme ich natürlich eine Fehlermeldung (Division durch Null). Wie kann ich mit FPScript dafür sorgen, dass bei einer Division durch Null eine Null als Ergebnis hinterlegt wird ?
Danke und Gruß
Ulli03.03.2006 um 18:24 Uhr #33321Martin UellenbergTeilnehmerHallo,
ich möchte die y-Werte von zwei Signalen (Signal1 und Signal2) durcheinander dividieren. Sobald der Wert des Divisors = 0 ist, bekomme ich natürlich eine Fehlermeldung (Division durch Null). Wie kann ich mit FPScript dafür sorgen, dass bei einer Division durch Null eine Null als Ergebnis hinterlegt wird ?
Danke und Gruß
Ulli03.03.2006 um 23:36 Uhr #33317Bernhard KantzTeilnehmerIn this case you can use the [b]Try…Catch…End[/b] statement.
Example:
[code]
Dim a, b
a = 1.
b = 0
Try
return a/b
Catch Exception
return ?
End
[/code]06.03.2006 um 18:04 Uhr #33318Martin UellenbergTeilnehmerHallo,
danke für die Antwort. Leider komme ich damit noch nicht zurecht. Nochmal mein Problem. Ich möchte zwei Signale (Signal1 und Signal2) durcheinander dividieren. An den Stellen, wo eine Division durch Null stattfindet, soll eine Null als Ergebnis raus kommen. Mit oben angegebener Lösung bekomme ich immer nur einen Wert als Ergebnis. Nicht aber einen neuen Datensatz (mit gleicher Werteanzahl wie Signal1 und Signal2).
Wie sieht die Formel dafür aus ?
Danke und Gruß
Martin06.03.2006 um 19:51 Uhr #33319Bernhard KantzTeilnehmerThere is a difference if the Y component of the signal contains integer or floating point values. If the signal contains integer values an exception will be thrown in case of a division by zero (see sample above).
With floating point values no exception is thrown, but the result will contain an invalid value (?) at the places where a division by zero occured.
The different behavior stems from the fact that there is no possibility to express an invalid value with integer values.This what you have to do: Execute the division as usual. Search and replace the invalid values by 0 afterwards:
[code]
dim a, b, ca = { 1., 2., 3., 4., 5., 6. }
b = { 3, 0, 2, 0, 11, 0 }
c = a / b
c[SearchVoidValues(c)] = 0
[/code]
Support
support@weisang.com06.03.2006 um 21:32 Uhr #33320Martin UellenbergTeilnehmerVielen Dank. So funktioniert es.
-
AutorBeiträge
- Du musst angemeldet sein, um auf dieses Thema antworten zu können.