Acquiring blocks of data
조회 수: 2 (최근 30일)
이전 댓글 표시
Ahmed Abdulla
2020년 7월 5일
답변: Vinai Datta Thatiparthi
2020년 7월 10일
I have a 100x100 matrix (Matrix A) and ive been trying to get a matrix B. Where each cell in matrix B contains an array of all the value that surround the corresponding cell in Block A in terms of a block with size N (Lets say its 2 for now). The results should be matrix B which is 100x100 where each cell contain an array of the surrounding data points. I hope this makes sense.
I would appreciate any help
댓글 수: 2
Voss
2020년 7월 5일
Maybe an example A that's 5x5 or so and the corresponding output B (still assuming N == 2, say) would clarify exactly what you have in mind.
jonas
2020년 7월 5일
What are you going to do with matrix B afterwards? Perhaps conv2 or blockproc functions could solve the problem without building matrix B.
채택된 답변
Vinai Datta Thatiparthi
2020년 7월 10일
Hey Ahmed,
Firstly, since your output should be a collection of arrays of different values and dimensions, using cell arrays is the correct way to go about solving the problem. This code is a simplified version of what you're trying to do:
matIn = randi(5,5,5); % The input matrix
% Insert the 100x100 matrix in your case
cellOut = cell(5,5); % Cell array to hold the output
matRef = zeros(size(matIn));
for i=1:numel(cellOut)
matRef(:) = 0;
matRef(i) = 1;
% Use convolution to get the neighbors
cellOut{i} = matIn(conv2(matRef,[1,1,1;1,0,1;1,1,1],'same')>0)';
end
Finally, to get the neighbors of any element in matIn with the indices (i,j), simply use
cellOut{i,j}
Further, to echo @Jonas thoughts, consider using conv2 in your application directly to get what you want, instead of having to go through these steps.
Hope this helps!
댓글 수: 0
추가 답변 (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!