Shift elements in a 3D array
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi,
I have a 3D array. I would like to remove few elements (say, I want to remove all 120s in the 3D array). Once I remove them, I would like to add zeros at the end to maintain the same vector length.
Could anyone please suggest an option to do this?
Thank you so much
댓글 수: 0
답변 (1개)
Voss
2022년 12월 3일
Here's an example with a 2x3x2 array, removing all the 9s and appending 0s:
data = reshape(1:12,[2 3 2])
siz = size(data);
idx = data == 9;
data(idx) = [];
data(end+1:end+nnz(idx)) = 0;
data = reshape(data,siz)
Notice the 10, 11, 12 are now in different locations. Is that what you want?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!