MATLAB: String into 3×3 Matrix

cell arraysstr2doublestring

Hey. My string is X = "1 0.8 0 0 1 0 0 0 1"
i want to seprate it with spaces and write it into 3×3 matrix. I have tried
Y = split(X);
Z = str2double(Y);
c2 = reshape(Z,3,3,[])
The output is :
c2 =
1.0000 0 0
0.8000 1.0000 0
0 0 1.0000
but it should be :
1 0.8 0
0 1 0
0 0 1
Please help me.

Best Answer