Message Boards Message Boards

0
|
2072 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Using a conditional function with TimeSeriesThread

Posted 2 years ago

Hello,

I have trouble using a function that hosts a "Which" function inside a TimeSeriesThread function.

This is a function I wrote, the Which function lies in it :

MyFunction = Function[{ts1,ts2,ts3},
Which[
(ts1-ts2)>=(2*(ts3-ts2)/3),1,
(ts1-ts2)>((ts3-ts2)/3)&&(ts1-ts2)<(2*(ts3-ts2)/3),0,
(ts1-ts2)<=(ts3-ts2)/3,-1]];

Let's suppose I have 3-time series named "TimeS1", "TimeS2" and "TimeS3" with numerical Values only. If I call my function inside a TimeSeriesThread :

TimeSeriesThread[myFunction[First[#],Take[#,2],Last[#]]&,{TimeS1,TimeS2,TimeS3}]["Path"]

the "Path" display prints this instead of the calculated values:

{{3818707200,Which[{0.,2.63041}≥{2.78062,4.53423},1,128.453-{128.453,125.823}> etc

Do you have any idea of how I could run properly my function inside a TimeSeriesThread?

Thank you!

POSTED BY: Clarisse Wagner
3 Replies
Posted 2 years ago

Probably not related to your question, but I think you can simplify

MyFunction[First[#],Part[#,2],Last[#]]&

to be just

Apply[MyFunction]
POSTED BY: Eric Rimbey

Thank you very much!

POSTED BY: Clarisse Wagner
Posted 2 years ago

I haven't checked your MyFunction for correctness, but the thing that jumps out at me is the Take[#,2] expression. That will produce a List. I think what you probably wanted was Part[#,2].

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract