Eliminate rows from an array

조회 수: 2 (최근 30일)
José Santos Pérez Leal
José Santos Pérez Leal 2021년 6월 12일
댓글: José Santos Pérez Leal 2021년 6월 12일
Hi everyone
How can I cut a 31450X1 array in order to obtain the same array with a dimension of 15725X1, eliminating the second half of rows from the original array? The array is a variable I'm working with, but I can't solve that problem. I tried it creating the next code:
LEN=length(data3);
for x=1:LEN
if x>(LEN/2)
ROW=LEN;
data3(ROW,:)=[];
end
end
Where data3 is the 31450X1 array, but the matrix index is out of range for deletion

채택된 답변

Image Analyst
Image Analyst 2021년 6월 12일
To eliminate the "second half of rows" (like you asked) from your column vector, do this:
midRow = ceil(length(data3) / 2);
data3 = data3(midRow : end);
To eliminate every other row, do this:
evenRows = data3(2:2:end); % Extract even numbered rows only.
oddRows = data3(1:2:end); % Extract odd numbered rows only.
  댓글 수: 1
José Santos Pérez Leal
José Santos Pérez Leal 2021년 6월 12일
Thank you very much!!! I will analize it in order to understand your method, thank you!!

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

추가 답변 (1개)

Mouhamed Niasse
Mouhamed Niasse 2021년 6월 12일
Hello, this is what you tried to achieve:
data3(1+length(data3)/2:length(data3),:)=[];
Try to run below example. Hope it helps you understand.
data3=ones(31450,1); % data3 initialized as row vector of size 31450x1
size(data3)
data3(1+length(data3)/2:length(data3),:)=[]; % Eliminate second half of rows
size(data3)
  댓글 수: 1
José Santos Pérez Leal
José Santos Pérez Leal 2021년 6월 12일
Thank you very much, Mouhamed!!! I'm going to analize your method in order to understand it, thanks!!

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

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by