Search code examples
stringmatlabvectorcharcell

How to extract Curly Braces Vector from Cell String in Matlab


I have the following string (char of 1X48) in cell in Matlab

{ {1 , 0 , 0 } , { 0 , 1 , 0 } , { 0 , 0 , 1 } }.

I am trying to get three separate strings in new line with just space, so that data will look like

1 0 0

0 1 0

0 0 1

I will really appreciate if anyone has any idea to covert in matlab.

Thanks


Solution

  • Better to use cell2mat function

    In your case you can try something like this,

    temp = { {1 , 0 , 0 } , { 0 , 1 , 0 } , { 0 , 0 , 1 } }; out = [cell2mat(temp{1, 1}); cell2mat(temp{1, 2}); cell2mat(temp{1, 3})]

    I hope it will help!!