フィルターのクリア

Make this recursion output to be a cell array

2 ビュー (過去 30 日間)
Meowooo
Meowooo 2018 年 10 月 10 日
回答済み: KSSV 2018 年 10 月 10 日
function P = myperms(v)
% simple recursive scheme to generate all permutations of a vector v.
n = numel(v);
if n <= 1
P = v;
else
P = zeros(factorial(n),n);
f = factorial(n-1);
L = 1:f;
for ii = n:-1:1
P(L,1) = v(ii);
P(L,2:n) = myperms(v(setdiff(1:n,ii)));
L = L + f;
end
end
Hi, this is the code I have for calculating a permutation of a double array. I am just wondering how could I turn the output to be a cell array. I tried to use "num2cell" but it failed. Thanks!

回答 (1 件)

KSSV
KSSV 2018 年 10 月 10 日
p = num2cell(p,2) ;

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by