0

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]
Cheng
  • 279
  • 3
  • 13
  • 1
    The way you show it now, `Ma{1,:}.'` is a cell array of strings, and you want to obtain a cell array of doubles (or any other numerical type). Is that correct? – Nick Aug 26 '14 at 09:04
  • Hi i understand that they are strings and i wish to convert them into numerical values. However, what i am stuck with, is to add square brackets to every single values. – Cheng Aug 26 '14 at 09:24

2 Answers2

2

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,:} );
Shai
  • 111,146
  • 38
  • 238
  • 371
  • Thanks. I have to go back to my original array to add in the square brackets, which is quite a hassle. – Cheng Aug 27 '14 at 02:21
0

You don't need to add the square brackets yourself. This just means that it is a numerical value in a cell.

In order to achieve this you should do the following, using both the num2cell as str2double functions:

newM = num2cell(str2double(Ma{1,:}))
Nick
  • 3,143
  • 20
  • 34