Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

eliminating some elements randomly from a matrix

1 Ansicht (letzte 30 Tage)
may
may am 8 Okt. 2013
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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.

Antworten (1)

Honglei Chen
Honglei Chen am 8 Okt. 2013
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,[])

Diese Frage ist geschlossen.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by