Search code examples
matlabmatrixcellsquare-bracket

matlab: Adding square brackets to all individual numerical values within cell arrays


I wish to add a cell array (Ma) into another cell array. However both needs to be of the same format (individual cells in square brackets).

For instance I have an array..

Ma{1,:}.'

ans =

Columns 1 through 8

'83.6'    '85.2'    '91'    '87.9'    '91.8'    '86.3'    '90.6'    '90.2'  

How do i add square brackets to all the numerical values of very individual cells?

Below is what i wish to obtain, it is also a 1x8 cell.

ans =[83.6]    [85.2]    [91]    [87.9]    [91.8]    [86.3]    [90.6]    [90.2]

Solution

  • Your cell values are strings (you can tell by the quote marks ' surrounding the values). You wish to convert them to numerical values ("add square brrckets around them" as you put it).

    To convert string to double you can use str2double command:

    M = str2double( M{1,:} );