Clear Filters
Clear Filters

함수에 가변적인 입력 인수를 넣는 법

2 views (last 30 days)
eblee
eblee on 21 May 2024
Answered: lazymatlab on 21 May 2024
사용자의 입력에 따라 셀형 배열을 만들고, 각 배열을 함수의 input으로 사용하고 싶습니다.
이때 배열 개수가 가변적이게 된다면 combinations에 입력을 어떻게 처리해야할지 문의드립니다...
signal_input{1} = [1];
signal_input{2} = [2,3];
signal_input{3} = [4,5,6];
signal_input{4} = [7,8,9,0];
.
.
.
signal_input{n} = {n, n+1...};
signal_comb = combinations(signal_input{1}, signal_input{2}, ..., signal_input{n}); //가변적인 n개의 배열을 함수 인수로 넣고싶습니다.

Accepted Answer

lazymatlab
lazymatlab on 21 May 2024
셀 배열에 대해서 {:}를 사용하면 comma separated list가 생성됩니다. 이것을 함수의 입력인자로 넣으면 됩니다.
c{1} = [1];
c{2} = [1, 2];
c{3} = [1, 2, 3];
combinations(c{:})
ans = 6x3 table
Var1 Var2 Var3 ____ ____ ____ 1 1 1 1 1 2 1 1 3 1 2 1 1 2 2 1 2 3

More Answers (0)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Tags

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!