Print the value of a multidimensional array with the output as compatible matlab code

Viewed 289

For matrices with dimensions equal or less then 2 the command is:

For instance:

>> mat2str(ones(2,2))

ans =

[1 1;1 1]

However, as the help states, this does not work for higher dimensions:

>> mat2str(rand(2,2,2))
Error using mat2str (line 49)
Input matrix must be 2-D.

How to output matrices with higher dimensions than 2 with that is code compatible, without resorting to custom made for loops?

1 Answers
Related