How to delete even Index from array and replace zero at the end MATLAB
6 次查看(过去 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
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!