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!