Reducing array size, discarding data

조회 수: 16 (최근 30일)
Ben Twill
Ben Twill 2021년 3월 23일
댓글: Ben Twill 2021년 3월 23일
I am trying to reduce the size of an array and discard any data that happens to fall out of the new bounds.
I currently have a loop where 'Array' is an array of larger size then 'Array_Temp'
for w=1:W
for h=1:H
Array_Temp(w,h) = Array(w,h);
end
end
newArray(:,:,k) = myArrayPart_temp;
I am wondering if there is a better way to do this as going through each element one by one is very slow!
  댓글 수: 1
KSSV
KSSV 2021년 3월 23일
discard any data that happens to fall out of the new bounds
This may not keep your matrix intact. Are you okay with that? You want to remove the entire row/ column?

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

채택된 답변

DGM
DGM 2021년 3월 23일
편집: DGM 2021년 3월 23일
No need for loops. Assuming these are mxnxk arrays:
childarray=parentarray(1:H, 1:W, :);
Or if you don't want to start in the corner:
childarray=parentarray(startrow:endrow, startcol:endcol, :);
You could also use imcrop(), though that's a bit frustrating to use in my opinion.

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by