Exporting table to excel

320 ビュー (過去 30 日間)
Javier Joya
Javier Joya 2016 年 6 月 27 日
コメント済み: Daniel 2023 年 7 月 3 日
Good Afternoon, I will try to keep this to the point. I have created two tables and they ready to be exported to excel. Say T1 is [1600x5] and t2 is [2x4]. How can I concatenate those two tables into one so then I will be able to use the "writetable" function? I have tried the "horzcat" and the "union" functions but I keep getting errors due to the dimensions not being the same. Is there a way around this?
Date = datetime('today'); M1 = table(Temp_K, Pressure, inverse_temp, N_Log, k_value_slope); (1600x5) Matrix M2 = table(MM, Date, Pan_Size, Experiment_Date); (2x4) matrix M = horzcat(M1, M2); M = table(Temp_K, Pressure, inverse_temp, N_Log, k_value_slope, MM, Pan_Size); name = input('Enter the name you wish to save the file as, use single quotes (ex. filename.xlsx) : '); writetable(M, name,'Sheet',1,'Range','B1');
  3 件のコメント
Javier Joya
Javier Joya 2016 年 6 月 27 日
I have tried this and still returns an error.
Sourin Dey
Sourin Dey 2016 年 6 月 27 日
  1. x=[1 2 3 6 ;4 5 6 51 ;7 8 9 2 ;10 11 12 11];
  2. y=[4 5 6;7 8 9];
  3. C = blkdiag(x,y);
  4. C(1:2,5:7)=y;
  5. C(5:6,:)=[] . thus [4*4] & [2*3] can be concatenated , or any other dimensions as well.

サインインしてコメントする。

採用された回答

Jan Orwat
Jan Orwat 2016 年 6 月 27 日
編集済み: Jan Orwat 2016 年 6 月 27 日
You don't have to join tables before exporting them. You can just create spreadsheet and then add other data in other sheets or in the same sheet, specifying target cells.
Maybe you would like separate sheets?
warning('off','MATLAB:xlswrite:AddSheet'); %optional
writetable(M1,'test.xlsx','Sheet',1);
writetable(M2,'test.xlsx','Sheet',2);
Or in one sheet:
writetable(M2,'test2.xlsx','Sheet',1);
writetable(M1,'test2.xlsx','Sheet',1,'Range','E1');
  3 件のコメント
ET
ET 2023 年 6 月 28 日
編集済み: ET 2023 年 6 月 28 日
Hello, how do you save the excel file (test.xlsx) in a specific directory. Thanks
Daniel
Daniel 2023 年 7 月 3 日
You can specify the directory in 'test.xlsx'.
writetable(M1,'C:\Users\JohnDoe\Documents\MATLAB\test.xlsx','Sheet',1);
You can find the working directory using pwd.
S = pwd + "\test.xlsx"
writetable(M1,S,'Sheet',1);
Replace S with the filepath and filename.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by