Define variable inputs for 'merge' function

1 回表示 (過去 30 日間)
Goryn
Goryn 2013 年 3 月 28 日
Hello,
could you please help me with the next problem.
I'm trying to merge N financial time series objects by function newfts = merge(fts1, fts2, ..., ftsx). How may I define a variable inputs for that? Because, when I have 2 time seriesobjects it becomes:
newfts = merge(fts1, ft2);
When I have 3:
newfts = merge(fts1, fts2, fts3);
How to avoid of examination of all posible options?
ATTENTION! Please, don't suggest to use a cell array
v={fts1,fts2,...,ftsn}
and use
function newfts = merge(v)
It doesn't work.

採用された回答

Jan
Jan 2013 年 3 月 28 日
編集済み: Jan 2013 年 3 月 28 日
It is strange, that you do not want us to post the best solution by using a cell array. Unfortunately you only claim, that "it does not work", but do not mention any details. Of course it works, when you add a little "{:}":
v = {fts1,fts2,...,ftsn}
newfts = merge(v{:})
Then merge() gets a comma-separated list exactly as if you call it as:
newfts = mergs(fts1, fts2, fts3); % Or how many elements v contains
In addition using a cell is a much better idea than naming the variables "fts1, fts2, ...". Using fts{k} would be more convenient, see http://www.mathworks.com/matlabcentral/answers/57445-faq-how-can-i-create-variables-a1-a2-a10-in-a-loop.
  1 件のコメント
Goryn
Goryn 2013 年 4 月 1 日
Thank you, Jan. Great answer.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by