MATLAB: Unable to perform assignment because the left and right sides have a different number of elements.

errorfor loopMATLAB

I'm trying to solve this problem in many ways but there is still the error like in the tittle
Script:
n1=1.35
y=0:0.01:0.8;
T3=zeros(length(y),1);
for a=1:length(y)
y(a)=y(a)/n1;
T3(a)=[1 y(a); 0 1];
end

Best Answer

The left side of this line of code refers to 1 element of T3. The right side refers to a 4 element matrix.
T3(a)=[1 y(a); 0 1];
You can't stuff a 4 element matrix into 1 element of a vector. It works about as well as stuffing 4 eggs into one of the cups in an egg carton without breaking any.
You could create a 3-dimensional array where each page of the array contains one of these matrices or you could create a cell array.
Related Question