Array dimensions must match for binary array op.

조회 수: 6 (최근 30일)
ACHALA SHAKYA
ACHALA SHAKYA 2019년 6월 19일
답변: Deepak 2025년 6월 5일
How to map these array to perform the function as, size of array A and B
size(A)
ans =
256 256 4
>> size(d)
ans =
1 1
inv = (eye(d) + 2*tau*gamma1*A)^(-1);

답변 (1개)

Deepak
Deepak 2025년 6월 5일
I understand that you are trying to perform a matrix operation involving arrays A and d, specifically computing an inverse expression like:
inv = (eye(d) + 2*tau*gamma1*A)^(-1);
However, your array A has size 256×256×4 and d is 1×1, which suggests a dimension mismatcheye(d) creates a 1×1 identity matrix, but you likely want an identity matrix matching the first two dimensions of A.
To fix the dimension mismatch and perform the intended operation for each 2D slice of A, you can loop through the third dimension and compute the inverse per slice:
tau = 0.1; % example scalar
gamma1 = 0.5; % example scalar
A = rand(256,256,4); % example A
inv_result = zeros(256,256,4);
for k = 1:size(A,3)
inv_result(:,:,k) = inv(eye(256) + 2*tau*gamma1*A(:,:,k));
end
This way, you correctly apply the inverse operation to each 256×256 matrix slice in A.
Please find attached the documentation of functions used for reference:
I hope this hleps.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by