How can I delete row based on the value of row (i) and row (i+1)
Mostra commenti meno recenti
Hi I am new to matlab, I am working with 1000*10 matrix. I want to delete the all row if the value in row (i) column 10 is the same as the value in row (i+1) column 10, and keep the row if the value in row (i) column 10 is not equal to the value in row (i+1) column 10. For example: my data file is X. and my code is, but it does not work with me :
for i=1:length (X)
if (X(i,10)~=X(i+1,10)
y(j,1:10)= X(i,1:10);
j=j+1;
else
y(j,1:10)=[];
end
if true
% code
end
end
Risposta accettata
Più risposte (1)
madhan ravi
il 25 Ott 2018
for i=1:length (X)
if (X(i,10)~=X(i+1,10)
y(i,:)= X(i,:);
else
y(i,:)=[];
end
end
2 Commenti
madhan ravi
il 25 Ott 2018
Modificato: madhan ravi
il 26 Ott 2018
Note: I didn’t per-allocate the array because the resultant matrix is unknown since you didn’t provide data but if you know the resultant matrix you can simply do
y =zeros(1000,10)
Gadelhag M Omar Mohmed
il 29 Ott 2018
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!