MATLAB: Creating a matrix in matlab using a text file

inputmatrixoutputpythontextfile

type output.txt;
A = readmatrix('output.txt');
A
This is the output.txt file
[[1 2 2 0 0]
[2 1 0 0 2]
[2 0 1 2 0]
[0 0 2 0 4]
[0 2 0 4 0]]
A =
NaN 2 2 0 NaN
NaN 1 0 0 NaN
NaN 0 1 2 NaN
NaN 0 2 0 NaN
NaN 2 0 4 NaN
but when i passed it as a input to A the first and last rows are displaying NaN.can someone rectify it.

Best Answer

It's the brackets, [], that confuses Matlab. Try
A = readmatrix( 'output.txt', 'Whitespace',' []' );
I have R2018b so I can't test it.
Your output.txt looks more like the right hand side of an assignment in an m-function. Try
A = [[1 2 2 0 0]
[2 1 0 0 2]
[2 0 1 2 0]
[0 0 2 0 4]
[0 2 0 4 0]]
in the command window (copy and paste).