Array dimensions must match for binary array op.

6 Ansichten (letzte 30 Tage)
ACHALA SHAKYA
ACHALA SHAKYA am 19 Jun. 2019
Beantwortet: Deepak am 5 Jun. 2025
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);

Antworten (1)

Deepak
Deepak am 5 Jun. 2025
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.

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by