MATLAB: Strings and numbers in the same matrix

string and numbersstring matrix

Ok, so I have a bunch of data. I want to store this data in some kind of matrix with rows and columns for easy usage. The data is made up of both strings and regular numbers, mixed. Storing the data as a matrix is fine (I've used a string matrix), but getting to the data afterwards prooves to be troublesome.
Getting the strings out are no problem, but I need to be able to calculate other stuff with the numbers. Since I've saved everything as a string matrix I can't just use the numbers as they are, so I tried using str2double, but that just returns NaN.
I've also tried using a regular matrix to store the data, but that just stores the strings in individual letters, which won't work at all, since the length of the strings themselves will vary between data sets.
Any ideas on how to solve this problem? It doesn't really matter if it's a string matrix or a regular one, as long as it works!
Thanks in advance, Erik

Best Answer

If you want to store numbers and strings in the same object, use a CELL:
C = cell(2, 2);
C{1, 1} = 1;
C{1, 2} = rand(10);
C{2, 1} = 'Hello';
C{2, 2} = {'This', 'is', 'a', 'sentence', 'as', 'cellstring'};