Delete rows from an array

조회 수: 3 (최근 30일)
Ricardo López
Ricardo López 2020년 12월 15일
댓글: Image Analyst 2020년 12월 15일
Good afternoon
I have a long array of numbers, CEC (52560x1) and I would like to delete the rows in the following way:
r = 1:1:8760
t = 0:1:8759
CEC((2+6*t):(6*r))
I tried to set it into a loop by:
for r = 1:1:8760
for t = 0:1:8759
CEC((2+6*t):(6*r)) = [];
end
end
But it is not working for me. Any ideas?
Thank you!
  댓글 수: 3
Ricardo López
Ricardo López 2020년 12월 15일
I want those rows empty, so the result would be an array of the same length with 0 in the desired values.
Image Analyst
Image Analyst 2020년 12월 15일
Please give some actual numbers. For example, what indexes represent the first set of rows to delete, and the second set of rows to delete?

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

채택된 답변

David Hill
David Hill 2020년 12월 15일
a=CEC(1:6:52560);
CEC=zeros(size(CEC));
CEC(1:6:52560)=a;

추가 답변 (1개)

SHIVAM KUMAR
SHIVAM KUMAR 2020년 12월 15일
편집: SHIVAM KUMAR 2020년 12월 15일
Your code will work like this if used on 1 D array .
CEC((2+6):end) = [0];
If you are using that your array shall be 52560X52560.
then you can use
for r = 1:1:8760
for t = 0:1:8759
CEC((2+6*t),(6*r)) = [0]; %Use a comma
end
end
  댓글 수: 1
SHIVAM KUMAR
SHIVAM KUMAR 2020년 12월 15일
ie. only have values for index 1 to 8 and all other indexes will be 0.

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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by