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.

 채택된 답변

Image Analyst
Image Analyst 2018년 9월 9일

0 개 추천

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.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2018년 9월 9일

0 개 추천

The only way to do this in excel would be to create a character vector from the values and store the character vector. Excel only permits one numeric value per cell.

카테고리

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by