Matrix with strings and numbers
5 ビュー (過去 30 日間)
古いコメントを表示
Dear all,
I have a column that contains thousands of the following elements (this is just a sample)
A=[ '2008-12-05 15:59:57'
'2008-12-05 15:59:57'
'2008-12-05 15:59:58'
'2008-12-05 15:59:58'
'2008-12-05 15:59:58'];
and I also have the following matrix that contains thousands of elements (this is just a sample)
B=[39.44 4900
39.44 100
39.44 200
39.44 100
39.44 100];
How can I get a matrix, say C=[A B]; and then save it in an excel?
Is there any code?
Please bear in mind that A and B contain thousands of elements.
Also to create A I used the command datestr(D,31);
Thank you in advance
0 件のコメント
回答 (2 件)
Ameer Hamza
2020 年 5 月 11 日
編集済み: Ameer Hamza
2020 年 5 月 11 日
Normal MATLAB array can only hold data of single type. You need to use cell array. Try something like this
A=[ '2008-12-05 15:59:57'
'2008-12-05 15:59:57'
'2008-12-05 15:59:58'
'2008-12-05 15:59:58'
'2008-12-05 15:59:58'];
B=[39.44 4900
39.44 100
39.44 200
39.44 100
39.44 100];
C = [num2cell(string(A)) num2cell(B)];
writecell(C, 'test.xlsx');
It will work on R2019a and later versions.
6 件のコメント
Ameer Hamza
2020 年 5 月 11 日
ektor, maybe you can try to set the 'UseExcel' option to false (although it should is false by default). Alternatively, you can also experiment by setting it to true
writetable(cell2table(C), 'test.xlsx', 'WriteVariableNames', false, 'UseExcel', false);
and
writetable(cell2table(C), 'test.xlsx', 'WriteVariableNames', false, 'UseExcel', true);
Also, open the MS Excel file and check what datatype the Excel considers this cell to be
01/12/2008 09:30
Steven Lord
2020 年 5 月 11 日
I recommend converting A into a datetime array and using that to create a timetable array.
参考
カテゴリ
Help Center および File Exchange で Data Import from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!