How to repeat elements of array in MATLAB

조회 수: 1 (최근 30일)
Med Future
Med Future 2022년 3월 10일
편집: Med Future 2022년 3월 10일
hello everyone i hope you are doing well
The data in the file is 250x1000, i have implemeneted the following code to delete 5% samples randomly from each row and replace zero at the end to complete the shape 1000 samples
Instead of zero, i want to repeat the array of each row from start complete the shape of 1000.
for example
in row 150 i have a data like data
[200 400 800 1000 800 200 400 ......]
When the below code run it remove 50 samples (950 samples remaining) and add 50 zeros (after 950) at the end of the row.
But i want to repeat the the row from start like [200 400 800 ....] will be added at the end of the row depend on the samples removes
How can i do it ?
dataset=load('datasetvalue').dataset;
[M,N] = size(dataset) ;
percentageMP=5;
size_MP=round(percentageMP/100*N);
Discards=nan(M,size_MP);
for i=1:M
row=dataset(i,:);
discard=randperm(N,size_MP);
row(discard)=[];
row(:,end+1:N)=0;
dataset(i,:)=row;
Discards(i,:)=discard;
end
Discards=sort(Discards,2);
  댓글 수: 2
Davide Masiello
Davide Masiello 2022년 3월 10일
Do you want to replace the zeros with the first values in the row before or after you have randomly deleted 5% of the elements in it?
Med Future
Med Future 2022년 3월 10일
편집: Med Future 2022년 3월 10일
@Davide Masiello Yeah, i want the first values after deleteing the elements

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2022년 3월 10일
Replace:
row(:,end+1:N)=0;
by
row(:,end+1:N) = row(1:size_MP);

추가 답변 (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