xlswrite cell array of strings to vertical array in Excel - goes wrong

Hi,
I have a series of timestamps that I want to write to Excel in the following way:
xlswrite(['mpSim_results_' fname(1:end-4) '.xlsx'], outputTimes(1:10), 'Sheet1','A2:A11');
And instead of writing 10 different values to A2:A11, the value outputTimes(1) gets written 10 times to the column A2:A11. When I change this to 'A2:J2' this works fine!
When I transpose the input, it still does not work, i.e. using outputTimes(1:10)' or outputTimes(1:10).' to write to A2:A11.
Why isn't this working? Using Matlab R2012b.
Kind regards, Lennart

Answers (1)

Try just 'A2' for range, not 'A2:A11'.
xlswrite(['mpSim_results_' fname(1:end-4) '.xlsx'], outputTimes(1:10), 'Sheet1','A2');
from the documentation for xlswrite:
"If you specify sheet, then xlRange can specify only the first cell (such as 'D2')."

2 Comments

thanks for the tip, but it did not work. I've tried not running my simulation and only importing the dates, and exporting them again. Then it works! So the problem lies somewhere in how I build up the dates cell array during my simulation, although I have no idea how..
I worked around it, by using timestamps in datenum format and just writing a double array to Excel. Change formatting in Excel and there are my dates. Just don't forget to subtract a specific number to convert from matlab to excel numeric dates (in my (default) case, that was 693960)

Sign in to comment.

Products

Asked:

on 4 Sep 2013

Community Treasure Hunt

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

Start Hunting!