Replacing values in a 4D array.
조회 수: 10 (최근 30일)
이전 댓글 표시
This is a question arising from this thread: https://www.mathworks.com/matlabcentral/answers/374453-round-number-closest-to-0-in-array But as it's a distinctly different question to the original post I thought to make another thread. However, if this is an issue please let me know.
I've indexed a 4D array,F, to locate the smallest values in each column of F using:
[~, idx] = min(abs(F(:,:,:,:)));
This gives me an array, 'idx', which contains the POSITIONS of the smallest elements in each column of F. For example,
F = [5 3 6; 4 6 1; 9 5 4] means idx = [2 1 2]. I then tried to replace these identified elements using
F(idx) = 0;
However, it's only replacing the first 5 elements of the first column of F with 0. I think this is because as F is a 4D array, when indexing it the elements are listed in a single column where the element positions are 1,2,3,4,5,6 etc... So the values identified in idx range from 1-5. So I think it's only replacing the first 5 elements of F as defined in the single column, rather than each individual column as I want it to.
So the question is how would I go about replacing the elements in each column of F as identified by idx.
댓글 수: 0
채택된 답변
Matt J
2017년 12월 26일
편집: Matt J
2017년 12월 26일
So the question is how would I go about replacing the elements in each column of F as identified by idx.
The elements refered to by idx are only the first occurraence of the minima in each column. If you really want all occurrences replaced do,
F(F==min(F,[],1))=0; %assumes R2016b or higher. Otherwise, use bsxfun
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!