Remove slices of 3D matrix

조회 수: 4 (최근 30일)
Erfaneh
Erfaneh 2014년 9월 6일
댓글: Erfaneh 2014년 9월 6일
I have a binary 3D matrix with 400 slices. I want to remove the slices (0 to 100) and (300 to 400) and I just want to keep the slices (100 to 300). I used from following code for removing 100 first slices:
  • for i=1:100
  • A(:,:,i)=[];
  • end
But above syntax code didn't remove 100 first slices, it removed 100 slices but not from the first. Can any one tell me where is the problem?

채택된 답변

Roger Stafford
Roger Stafford 2014년 9월 6일
편집: Roger Stafford 2014년 9월 6일
That is because after removing the first "slice", slice number 2 becomes number 1 and when you attempt to remove slice 2 it is actually the original slice 3 that is taken out. In other words in terms of original slice numbers you are removing the first 100 odd-numbered slices, 1,3,5,7,.... Also the slice numbers you quote are inconsistent - there are 101 slices in 0 to 100 and 300 to 400 and you would have 201 left in 100 to 300. Also there is no slice 0 in terms of index numbers.
I'll assume you want to remove the first and last 100 leaving the middle 200. Do this:
A(:,:,[1:100,301:400]) = [];
  댓글 수: 1
Erfaneh
Erfaneh 2014년 9월 6일
Thank you very much. My problem has been solved.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by