MATLAB Answers

how can i export a numeric vector that starts from 0 eg. 0001 from matlab to excel?

3 views (last 30 days)
ccc7
ccc7 on 11 Feb 2019
Commented: Jeremy Hughes on 11 Feb 2019
how can i export a numeric vector that starts from 0 eg. 0001 from matlab to excel?

Answers (6)

Jeremy Hughes
Jeremy Hughes on 11 Feb 2019
What's happening when you pass "0001" into a spreadsheet is the same thing that would happen if you typed that number into the spreadsheet from the Excel application. It converts the internal storage to "number". If you want to preserve exact text, add a single quote mark before the text, e.g. "'0001". (or {'''0001'} for cells.) This is the same thing you'd need to do if you tried tying the number into the Excel application to preserve the leading zeros.
This only happens on Windows when communicating with an active Excel process. If you're in the most recent release, you can also use the "UseExcel",false parameter, which won't do any post processing to the text; it is stored as-is. If you do, however, opening the file in Excel and re-saving might modify the contents.
  1 Comment
madhan ravi
madhan ravi on 11 Feb 2019
So I am using a Mac but the OP maybe using windows which may be the effect of this you say?

Sign in to comment.


madhan ravi
madhan ravi on 11 Feb 2019
Use xlswrite() or writetable().
  2 Comments

Sign in to comment.


ccc7
ccc7 on 11 Feb 2019
Hi,
Thank you for the code; however, stil the same issue. It seems that excel does accept 0s before a number. Is this true?


ccc7
ccc7 on 11 Feb 2019
what version do you use? I am using 2017b. Still does not work.
readtable.PNG
  3 Comments

Sign in to comment.


ccc7
ccc7 on 11 Feb 2019
hi all,
i am using pc. I tried Jeremy's suggestion (i.e., {'''0001'} ) and works fine!!!!
You have saved me from a lengthy manual work. now it is automated.
Thank you both.

Community Treasure Hunt

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

Start Hunting!