最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

arrays - Find the page in a 3D matrix that is closest to a given matrix - Stack Overflow

programmeradmin1浏览0评论

One can easily concatenate (stack up) four arrays by using:

B = cat(3, A, A, A, A); % here A is 2-dimensional M x N matrix and B is 3-dimensional M x N x 4 stack

How is it possible to concatenate (stack) n arrays to get M x N x ... x n array? The dimenisonality of A array is known (or easy to figure as numel(size(A)))

B = A; % A is M x N 2-dimensional array here
for ii = 1 : n-1
  B = cat(3, B, A);
end

is very poor,

B = nan([size(A),n]);
for ii = 1 : n
  B(:, :, ii) = A;
end

is quite slow too.

The motivation is to find the array in S-stack that is closest to the array A.

If I want to find element of vector S closest to a scalar a it is super simple:

distances = abs(S - a);
FOO = find(distances == min(distances),1);

but this opperation S - a works only for arrays of same size or when a is a scalar.

In more general manner I want to perform a dot-opperation on B and A, like B.*A, B./A, etc.

发布评论

评论列表(0)

  1. 暂无评论