MATLAB: How to put a vector into one cell in excel

excelexporting to excelMATLABvector

So, I have a vector uni=[0 1] and I'm wondering if there's a way to export this vector into a single cell in excel. I actually have multiple vectors such as this and they have different lengths – the longest has 3 values. Ideally when I look the excel file it will display: 0,1 or 0 1 for a cell. Have in mind that I'm trying to run this code for multiple data files which means that not all 'uni' vectors will be the same length. For example: Data 1: uni = [1 0]
Data 2: uni = [2 1 0]
Note that I'm not trying to put those data files together, I just want separate excel files for each of them that contain a single cell that has the 'uni' values.
I'm not sure if this is possible or simple, I'm just curious about it.

Best Answer

You need to create a string from the vector, then put the string into a cell, otherwise if you just use xlswrite() to write out the string, you'll get one character per Excel cell. If the string is in MATLAB cell, it will go into one Excel cell. Like
str = sprintf('%d ', integerVector); % Put all the numbers into a string.
str = sprintf('[%s]', str); % Enclose in square brackets.
ca = {str}; % Put string into a cell
xlswrite(xlFileName, ca, sheetName, 'A1'); % Poke into Excel cell A1.
Related Question