필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

eliminating some elements randomly from a matrix

조회 수: 1 (최근 30일)
may
may 2013년 10월 8일
마감: MATLAB Answer Bot 2021년 8월 20일
Suppose that I have a Matrix A and I want to eliminate k elements randomly from each column (1<=k<size(A,1))
so the remaining matrix, A' , would have the size equal to:
size(A',1)=size(A,1)-k, size(A',2)=size(A,2)
How can I do this? Thank you.

답변 (1개)

Honglei Chen
Honglei Chen 2013년 10월 8일
A = magic(5)
k = 2;
[M,N] = size(A);
ridx = zeros(k,N);
for m = 1:N
ridx(:,m) = randperm(M,k);
end
cidx = repmat(1:N,k,1);
B = A;
B(sub2ind([M N],ridx(:),cidx(:)))=[];
reshape(B,M-k,[])

이 질문은 마감되었습니다.

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by