MATLAB: How to create a 2×2 matrix out of 4 matrices

matrices

I have 3 matrices, each of size 1×100000 and the fourth element is a single numerical value. I am trying to make a square matrix 'Z' of size 2×2 which shall contain each of these 4 elements and do some operations on its inverse.
Could you please tell how I can do that?

Best Answer

After you create z as above, then a simple loop can calculate the inverse over the third dimension:
>> invz = zeros(2,2,100000);
>> for zi = 1:100000,
>> invz(:,:,zi)=inv(z(:,:,zi));
>> end
Don't neglect the preallocation of memory in that first line.
I feel like there may be a may to do all the inverse in one fell swoop (with accumarray?), but it's not coming to me. The loop above only takes a couple seconds on my machine.