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

8 次查看(过去 30 天)
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

采纳的回答

Jan
Jan 2022-3-3
"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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by