0

I have a variable with nested cells:

hello =   
    '8'     {1x3 cell}    {1x3 cell}
    '22'    {1x3 cell}    {1x3 cell}
    '97'    {1x3 cell}    {1x3 cell}

How do I write this into a single Excel file using MATLAB, e.g. xlswrite('file',hello)?

Eitan T
  • 32,660
  • 14
  • 72
  • 109
slowhead
  • 5
  • 5
  • As a reference, hello = {'8',{'a1','b1','c1'},{'a2','b2','c2'};'22',{'a3','b3','c3'},{'a4','b4','c5'};'97',{'a5','b5','c5'},{'a6','b6','c6'}} ; – slowhead Mar 12 '13 at 22:07
  • What exactly do you want to do? Write value '8' in A1, 'a1' in B1, 'b1' in C1, etc., and then '22' in A2, 'a3' in B2, etc.? – Eitan T Mar 12 '13 at 23:00
  • Yes EitanT :) Any help is appreciated – slowhead Mar 13 '13 at 06:57
  • 1
    Actually, I solved the problem. Not the most elegant way of doing it, but I for-looped iscell to see if the element is cell and if yes, I "flattened' the cell. – slowhead Mar 13 '13 at 20:21
  • It's a good idea to post your code for future reference. Maybe you can also get suggestions about improving it. – Eitan T Mar 13 '13 at 21:17

1 Answers1

0

Just looked into it after a while. Here is my solution with a sample problem.

clear all; clc ;

d = {{'Number'},{'Class A'},{'class B'};{'007'},{'Test One'},{'Test Two'}};

for i = 1:size(d,1)

for j = 1:size(d,2)

    if iscell(d(i,j))

        d(i,j) = d{i,j};

    end
end

end

xlswrite('FileAddress',d);

slowhead
  • 5
  • 5