Reducing array size, discarding data

8 Ansichten (letzte 30 Tage)
Ben Twill
Ben Twill am 23 Mär. 2021
Kommentiert: Ben Twill am 23 Mär. 2021
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 Kommentar
KSSV
KSSV am 23 Mär. 2021
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?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

DGM
DGM am 23 Mär. 2021
Bearbeitet: DGM am 23 Mär. 2021
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.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by