Can someone explain this please?

조회 수: 11 (최근 30일)
matmat lab
matmat lab 2016년 11월 6일
댓글: matmat lab 2016년 11월 6일
I know this is from the function perms but i dont understand how it works. from this part onwards:
q = permsr(1:n-1); % recursive calls
m = size(q,1);
P = zeros(n*m,n);
P(1:m,:) = [n*ones(m,1) q];
for i = n-1:-1:1,
t = q;
t(t == i) = n;
P((n-i)*m+1:(n-i+1)*m,:) = [i*ones(m,1) t]; % assign the next m
% rows in P.
end
P = V(P);
end
  댓글 수: 2
Jan
Jan 2016년 11월 6일
편집: Jan 2016년 11월 6일
As long as neither "permsr" nor "n" is defined, wild guessing is required to answer your question. Please post the complete code and ask a specific question. How much time should I spend to explain the meaning of "m = size(q,1)" or do I have to explain the zeros command?
matmat lab
matmat lab 2016년 11월 6일
function P = permsr(V)
% subfunction to help with recursion
V = V(:).'; % Make sure V is a row vector
n = length(V);
if n <= 1
P = V;
return;
end
q = permsr(1:n-1); % recursive calls
m = size(q,1);
P = zeros(n*m,n);
P(1:m,:) = [n*ones(m,1) q];
for i = n-1:-1:1,
t = q;
t(t == i) = n;
P((n-i)*m+1:(n-i+1)*m,:) = [i*ones(m,1) t]; % assign the next m
% rows in P.
end
P = V(P);
end
This is the full code but i dont get why is there the [n*ones(m,1) q] and like the purpose of t and q and P((n-i)*m+1:(n-i+1)*m,:) = [i*ones(m,1) t] Basically i dont understand what it is doing

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by