How to delete even Index from array and replace zero at the end MATLAB

11 views (last 30 days)
I have the code which delete 5% of random index from the dataset and add zero at the end .
i just want to delete even index sample from the array and add zero at the end
discard= delete the random sample from array
load('datasetvalue.mat')
[M,N] = size(dataset) ;
percentageMP=5;
size_MP=round(percentageMP/100*N);
Discards=zeros(M,size_MP);
for i=1:M
MP=dataset(i,:);
discard=randsample(N,size_MP);
MP(discard)=[];
MP(:,end+1:N)=0;
MPV(i,:)=MP;
Discards(i,:)=discard;
end

Accepted Answer

Jan
Jan on 3 Mar 2022
"delete even index sample from the array and add zero at the end"
Maybe:
X = rand(10, 10); % Arbitrary test data
X(2:2:end, :) = []; % Delete rows with even indices
X(10, 10) = 0; % Fill with zeros implicitly

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!