3

I need to output a cell to an excel file. Before this I need to convert a date column of integers to datestrings. I know how to do this, but I am not able to put this new string array back into the cell -

mycell = { 'AIR' [780] [1] [734472] [0.01] ; ...
           'ABC' [780] [1] [734472] [0.02]}

I did this -->

dates = datestr(cell2mat(mycell(:,4))) ;

What I need as an answer is:

{'AIR' [780] [1] '14-Dec-2010' [0.01] ;
 'ABC' [780] [1] '23-Dec-2010' [0.03] ; }

so that I can now send it to an excel file using xlswrite.m

2 Answers 2

3
mycell = { 'AIR' 780 1 734472 0.01] ; ...
           'ABC' 780 1 734472 0.02]}

mycell(:,4) = cellstr(datestr(cell2mat(mycell(:,4))))

mycell = 

    'AIR'    [780]    [1]    '30-Nov-2010'    [0.01]
    'ABC'    [780]    [1]    '30-Nov-2010'    [0.02]
Sign up to request clarification or add additional context in comments.

Comments

1

One alternative that avoids the conversions is to use the function CELLFUN:

mycell(:,4) = cellfun(@datestr,mycell(:,4),'UniformOutput',false);
%# Or an alternative format...
mycell(:,4) = cellfun(@(d) {datestr(d)},mycell(:,4));

Both of the above give the following result for your sample cell array:

mycell = 

    'AIR'    [780]    [1]    '30-Nov-2010'    [0.0100]
    'ABC'    [780]    [1]    '30-Nov-2010'    [0.0200]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.