Joining two columns and exporting to excel

조회 수: 5 (최근 30일)
Adnan Jayyousi
Adnan Jayyousi 2022년 6월 25일
편집: Abderrahim. B 2022년 6월 25일
Hello,
I have the following arrays, I want to join them into one matrix and export them as .xlsx file.
be mindful thae B is datetime, i tried to do it in the simple way creating a matrix but it gives error, any conversion may be needed here ?
thanks

채택된 답변

Amritesh
Amritesh 2022년 6월 25일
편집: Amritesh 2022년 6월 25일
1. To merge two arrays into one table
newTable = table(A,B);
2. To export newTable as .xlsx file
writetable(newTable,'newTable.xlsx');
Hope this solves your problem.

추가 답변 (2개)

Jonas
Jonas 2022년 6월 25일
use mat2cell before joining them!
[mat2cell(A) mat2cell(B)]

Abderrahim. B
Abderrahim. B 2022년 6월 25일
편집: Abderrahim. B 2022년 6월 25일
Hi !
You are trying to concatenate datetime array with an array of data type double that is why you got that error.
  • Check this answer maybe it answers your question.
  • Here is another way that I propose to export to spreadsheet.
  1. Create a table and populate it with your 2 arrays
  2. Use writetimetable to export to excel.
%% Example
% Dummy arrays
dTime = datetime(2013,11,1,8,0,0):datetime(2013,11,20,8,0,0) ;
fArray = 1:20 ;
% Populate the table
concatArrays = timetable(transpose(dTime), transpose(fArray), 'VariableNames',"Number" ) ; % transpose the array if they are row vectors
% Export to excel
writetimetable(concatArrays, 'Concatenated.xlsx')
Hope this solves your issue!

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by