0

I have a mxn financial time series object (fints) called data. Now I'd like to merge each of its n series into a new fints by keeping only the intersecting dates (the series headers are all unique).
Here's what I do:

headers = fieldnames(data,1);         %get the headers.
series = strcat('data.', headers);    %list of the series to be merged.
new_fints = merge(series{:},...       %merge the series.
               'DateSetMethod','Intersection');

But this gives me the following error: Undefined function 'merge' for input arguments of type 'char'.

What's wrong with my comma-separated list?

bluebox
  • 555
  • 1
  • 8
  • 19
  • Maybe nothing. There error message does not complain about that, it tells you Matlab can't find the `merge` function. What does `which merge` give you? – sebastian Dec 19 '13 at 12:01
  • Hm, you realize that `series = strcat('data.', headers);` gives a list of strings? It seems you actually want the value of all fields...? If so `series = struct2cell(data);` should probably do what you want. – sebastian Dec 19 '13 at 12:08
  • 1
    You're wrong there. The `merge` function is actually a method and takes series objects as inputs - not the names of variables where you have stored those. Due to MATLABs function scoping rules, the function hence can't be found for `char` inputs. From the docs on the arguments: `Comma-separated list of financial time series objects to merge.` (http://www.mathworks.de/de/help/finance/merge.html) – sebastian Dec 19 '13 at 12:20
  • @sebastian Ah, I see..that's my mistake. Do you have a better/working idea for how to merge all of the ``n`` series in ``data``? – bluebox Dec 19 '13 at 12:31
  • See my second comment. I'll also formulate it as an answer - if it helps please accept it :) – sebastian Dec 19 '13 at 12:39

1 Answers1

0

You'll want the actual field-values, e.g. like this:

series = struct2cell(data);

as in

>> struct2cell(struct('a', 1, 'b', 2, 'c', 3))
ans = 
    [1]
    [2]
    [3]

This should give you a cell array with all field values, and your rest of your code should work as intented.

sebastian
  • 9,526
  • 26
  • 54
  • I really appreciate your effort to help me out, but I'm afraid ``series = struct2cell(data);`` is not the solution to my problem. – bluebox Dec 19 '13 at 12:54
  • Well, then what's the issue? Any error message? Note that this assumes that all fields of `data` contain a `financial timeseries` object - if any field contains something different, this won't work – sebastian Dec 19 '13 at 13:07
  • This it what is returned from ``series = struct2cell(data);`` if "data" is a 3791 x 10 fints: https://www.dropbox.com/s/q49nohqznaiequd/screenshot2.png – bluebox Dec 19 '13 at 13:26
  • dropbox is blocked on my machine :p But if your `data` already is a `fints` than of course this makes no sense, I assumed it would be a struct. Why not do `merge(data,...)` ? – sebastian Dec 19 '13 at 13:30
  • I tried ``merge(data,'DateSetMethod','Intersection')`` but it gives this error: _Attempt to reference field of non-structure array. Error in fints/merge (line 502) holdIntDates = intersect(fts.data{3}, varargin{iidx}.data{3});_ – bluebox Dec 19 '13 at 13:42