How do I create a function that takes a vector of arbitrary length as an input argument and randomly permutes it as an output argument using the identity matrix, without using the randperm command?
3 ビュー (過去 30 日間)
古いコメントを表示
function [ x ] = myPerm(A)
A = ()
myLength = length(A)
I = eye(length(A))
end
this is what I have, I need help creating the arbitrary length and permuting the matrix
4 件のコメント
Walter Roberson
2018 年 12 月 11 日
you have not put in any version information and full code generation is currently supported for randperm .
If permutation of aa vector is needed then why bother with an identity matrix ?
Sorry but this is sounding like a homework assignment not a real task.
回答 (2 件)
Bruno Luong
2018 年 12 月 11 日
Fisher–Yates shuffle
for i = length(A):-1:2
j = ceil(i*rand);
A([i,j]) = A([j i]);
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!