Array dimensions must match for binary array op.
6 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
回答(1 个)
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 mismatch — eye(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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!