MATLAB: I want to creat a m matrix = [m1 0;0 m2] with varying m2 parameters in the m matrix.

for loopMATLABmatrix manipulation

I want to creat a m matrix = [m1 0;0 m2] with varying m2 parameters in the m matrix.
kindly sugggest me how to write the code.
I've written the following wrong code
m1=1;
m2=0.01:0.01:0.1;
for i=1:length(m2);
m(i)=[m1 0;0 m2(i)]
end
i=i+1;
The output whould be like
m(1) =
1.0000 0
0 0.0100
m (2)=
1.0000 0
0 0.0200
m (3)=
1.0000 0
0 0.0300 … so on

Best Answer

m1 = 1 ;
m2 = 0.01:0.01:0.1 ;
N = length(m2) ;
m = zeros(2,2,N) ;
m(1,1,:) = m1 ;
m(2,2,:) = m2 ;