how can i export a numeric vector that starts from 0 eg. 0001 from matlab to excel?
조회 수: 2 (최근 30일)
이전 댓글 표시
how can i export a numeric vector that starts from 0 eg. 0001 from matlab to excel?
댓글 수: 1
답변 (6개)
Jeremy Hughes
2019년 2월 11일
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
madhan ravi
2019년 2월 11일
편집: madhan ravi
2019년 2월 11일
So I am using a Mac but the OP maybe using windows which may be the effect of this you say?
madhan ravi
2019년 2월 11일
Use xlswrite() or writetable().
댓글 수: 2
madhan ravi
2019년 2월 11일
Hi Madhan
I do use xlswrite. The goal here is to add subject's id number (eg. 0001) in the fisrt collumn of each tab.
the code that i am using is
subjectid = cellfun(@num2str,{'0001'},'un',0)
xlswrite('temp.xlsx',subjectid)
But as you can see in the attached file, the exported value is '1'.
It would be great if i am able to export this value as '0001' from matlab to excel.
Any help would be very appreciated.
ccc7
2019년 2월 11일
댓글 수: 1
madhan ravi
2019년 2월 11일
I haven‘t checked the excel file but the data is preserved. Try
readtable('xxx.xlsx')
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!