How to automatically input function arguments?

6 ビュー (過去 30 日間)
Sheet Topno
Sheet Topno 2023 年 3 月 18 日
コメント済み: Sheet Topno 2023 年 3 月 18 日
I have to ask the user for the values of 'n'. I have two defined variables 'a' and 'b' which are vectors. I have to substitute 'a' and 'b' in the function allcomb() in a manner that 'a' occurs 'n' times followed by 'b'.
For example if n=5 then I need the value of allcomb(a, a, a, a, a, b).
For n=2, allcomb(a, a, b) is required.
How should I write a code which decides the input arguments?
Thank you.

採用された回答

DGM
DGM 2023 年 3 月 18 日
編集済み: DGM 2023 年 3 月 18 日
Assuming that allcomb() takes a variable-length argument list, this is one way.
% inputs
n = 2;
a = [1 2];
b = [3 4];
% create expanded argument list
args = [repmat({a},[1 n]),{b}];
% use it
x = allcomb(args{:});
  1 件のコメント
Sheet Topno
Sheet Topno 2023 年 3 月 18 日
Thank you 🙏

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by