使用Matlab将string写入excel?

我正在从Matlab写入一个string数组到Excel中。 我有一个单元arrays数据{},我试图写入Matlab。 它应该写三个很长的string,因为strcmp通过了3次。 目前只是把最后一组string写入excel。 data = {{1×25} {1×35} {1×20}}看起来像这样。 我也希望能够将数据写入三个单元格,而不是复制到与单元格数组元素中的行数一样多的单元格中。 这是可能的与Matlab做到优秀?

done = {} for i = 1:3 q = strcmp(x_gene_ID{i},locus_tags{i}); if q ==1 done{end+1} = data{i}; disp(done); end end w = xlswrite('data.xlsx',done','E2:E400'); 

好吧,帮助我知道单元格arrays的大于3单元格范围。 我想获得Nx1单元格数组,以适应Excel中的一个单元格,因为它需要对应于相邻单元格中的信息。 这是完全可能的吗?

 ABCDE w Rv0146 na Rv0039c (i want the cell array1 to go here) s Rv0156 na Rv0029c (i want the cell array2 to go here) s Rv0156 na Rv0029c (i want the cell array2 to go here) 

这是我期待在Excel中做的

更新的答案:

如果我理解正确,看起来你的variablesdata是一个单元格数组,其中每个单元格包含一个1乘N(或可能是N乘1)的string单元arrays。 如果您想尝试将这些单元格的每个string数组合并到电子表格的一个单元格中,则需要先将每个单元格格式化为一个长string。

下面是一个例子,说明如何通过将string的单元格数组连接在一起并使用换行符来格式化单元格数组:

 data = {{'hello' 'hi' 'hey'} ... %# Sample cell array of 1-by-N {'world' 'earth' 'everyone'} ... %# cell arrays of strings {'blah' 'blah'}}; data = cellfun(@(x) {strcat(x,{char(10)})},data); %# Add newline characters %# to the string ends data = cellfun(@(x) {deblank([x{:}])},data); %# Concatenate the inner cells and %# remove the trailing newlines 

现在,每个string的单元格数组只是一个单独的长string,每个string都可以写入Excel电子表格的单元格中,如下所示:

 xlswrite('data.xls',data(:),'Sheet1','E2'); %# Write the data to cells E2 to E4 

以下是生成的电子表格的样子:

替代文字

如果使用空格而不是换行符,则这是电子表格的样子(调整行和列宽度后):

替代文字

上述代码中使用的函数: CELLFUN , STRCAT , CHAR , DEBLANK , XLSWRITE 。