フィルターのクリア

Correlation of 2D matrix and 3D Matrix

1 回表示 (過去 30 日間)
Antonio Sereira
Antonio Sereira 2017 年 3 月 17 日
回答済み: BhaTTa 2024 年 6 月 12 日
Hi,
I have a 3D matrix/array A and a 2D matrix/array B. I want to correlate index B(i,j) to A(i,j,k) where the element (1,1) of B is equal to element (1,1,k) of A. How do I do this?

回答 (1 件)

BhaTTa
BhaTTa 2024 年 6 月 12 日
To correlate an element B(i,j) of a 2D matrix B with an element A(i,j,k) of a 3D matrix A where B(i,j) is equal to A(i,j,k) for some k, you essentially need to find the k value for each (i,j) pair where this condition is satisfied. This implies searching through the third dimension of A for each (i,j) pair to find the k that makes A(i,j,k) equal to B(i,j).
Assuming that for each (i,j) there is only one such k, and also assuming that the matrices A and B are related as described, you can perform this search using MATLAB. Here's a conceptual approach:
Step-by-step Approach
  1. Initialize: Create an output matrix K of the same size as B to store the k values.
  2. Loop through B: For each element in B, search through the corresponding stack in A to find the matching k.
  3. Store the k value: Once the correct k is found, store it in K.
% Assuming A is your 3D matrix and B is your 2D matrix
A = rand(5,5,10); % Example 3D matrix (for demonstration)
B = A(:,:,5); % Example 2D matrix taken from the 5th layer of A
% Initialize K with zeros
K = zeros(size(B));
% Loop through each element in B
for i = 1:size(B,1) % Rows
for j = 1:size(B,2) % Columns
% Find the k for which A(i,j,k) is equal to B(i,j)
% This example assumes there's always a match
for k = 1:size(A,3) % Depth/3rd dimension
if A(i,j,k) == B(i,j)
K(i,j) = k; % Store the k value
break; % Exit the loop once the match is found
end
end
end
end
% Display the K matrix
disp(K);
This method provides a basic framework to correlate elements between a 2D and a 3D matrix based on your specified condition. Adjustments may be necessary depending on the exact nature of your data and requirements.

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by