MATLAB: How to convert strings stored in a cell array to numbers

cell arrayfloatsgetting startedstrings

I have an array with strings in it – the format is the following:
'Name' '2/8' '3/7' '7/8'
Each of the above is its own cell within the array – i think this is called a cell array (i have not dealt with strings in matlab before)
What i want is the same matrix, except I want to remove the '' in each cell, and I want to actually DO the divisions. i.e '2/8' becomes 0.25 etc
how do i exract the name from 'Name', put it in the first column, then the next columns become the actual values rather than just a string containing characters.
P.S I am not putting the '' in the example for this post, it is actually there in the cell.

Best Answer

Hi Alex, you cannot mix double values with char values, but you still have to use a cell array (or drop the header 'Names').
% Suppose your input is:
c = {'Name' '2/8' '3/7' '7/8'}
EDIT (from Walter Roberson syntax, didn't know str2num behavior with operators) :
% Then your output would look like this:
[c(1); cellfun(@str2num,c(2:end),'un',0).']
ans =
'Name'
[0.2500]
[0.4286]
[0.8750]
Note that the ' are just there tell you that you're using a cell array of strings, but the actual content of each cell doesn't have them at all.
For more info Cell Arrays
Oleg