MATLAB: Hello. I am new to matlab and I have this problem. I need to store 91 different 3×3 matrices. Yet I get this error ‘Subscripted assignment dimension mismatch.’ Can someone help me out. Many thanks

for loopmatrix

thetha=0:1:90;
for i=1:length(thetha)
c(i)=cosd(thetha(i));
s(i)=sind(thetha(i));
T(i)=[c(i)^2 s(i)^2 -2*s(i)*c(i); s(i)^2 c(i)^2 2*s(i)*c(i);s(i)*c(i) -s(i)*c(i) (c(i)^2)-(s(i)^2)];
end

Best Answer

You could store them in a 3D array like this:
T = zeros(3,3,numel(thetha)); % pre-allocate outside the loop
:
T(:,:,i) = [c(i)...etc
Then downstream in your code when you want to use the i'th 3x3 matrix you simply use the syntax T(:,:,i)
What you are currently doing doesn't work because you can't stuff a 3x3 matrix into a 1x1 spot of T.