开发者

Writing a cell array of strings to Excel from Matlab?

开发者 https://www.devze.com 2023-03-13 15:15 出处:网络
I want to write the names of genes into excel but when I run this code matlab doesnt write anything into excel. The cells I want filled are l开发者_开发知识库eft blank. I cant seem to figure out what

I want to write the names of genes into excel but when I run this code matlab doesnt write anything into excel. The cells I want filled are l开发者_开发知识库eft blank. I cant seem to figure out what I am missing in my code. names is a cell array of string names.

function nameWriter()

x = importdata('mitominerratmitochondrialoutermembraneproteins');

names = {};
n = length(x.textdata);
counter = 0;
for i = 1:n
    if  strncmp(x.textdata(i),'>', 1) ==1
        names{end+1} = x.textdata(i);
        counter = counter +1;
    end
end

xlswrite('aacount2.xls', names, 'B1:CB1');
end


I believe the likely source of your error is that you are not taking into account that x.textdata is going to be a cell array of strings (as described in the table in the IMPORTDATA documentation for the output argument A). When you assign data to names like so:

names{end+1} = x.textdata(i);

You are actually placing a cell array inside another cell array, and XLSWRITE apparently can't handle nested cell arrays (i.e. it outputs blank fields for cell elements of the input that contain cell arrays). You should instead use curly braces, not parentheses, to access the cell contents of x.textdata, like so:

names{end+1} = x.textdata{i};
0

精彩评论

暂无评论...
验证码 换一张
取 消