How to set names to each colunm and row using "writematrix"?

63 ビュー (過去 30 日間)
Tony Castillo
Tony Castillo 2022 年 2 月 9 日
コメント済み: Tony Castillo 2022 年 2 月 9 日
Dear Mathcoders,
I just wonder how to name the colunms and rows of table done by using writematrix, have not found a workaround for this yet:
B=flip([Irr_ SOC_ PV_Harvest_ Mean_consump ElecEnergy_cons PVenergy_ ...
Power_Batt_ heating_c_ Cooling_c HDW_c EV_ Sp_ Power_Build_]);
Labels=["Irr", "SOC", "PVHarvest", "Mecons", "ElecEne", "PVen", "PBatt", "heatc", "Coc", "HDc", "EV", "Sp", "PBuild"];
writematrix(B, Labels, 'Means.xls')

採用された回答

Turlough Hughes
Turlough Hughes 2022 年 2 月 9 日
You can use writetable for this as follows:
B = rand(100,13);
Labels=["Irr", "SOC", "PVHarvest", "Mecons", "ElecEne", "PVen", "PBatt", "heatc", "Coc", "HDc", "EV", "Sp", "PBuild"];
writetable(array2table(B, 'VariableNames', Labels), 'Means.xls')
  1 件のコメント
Tony Castillo
Tony Castillo 2022 年 2 月 9 日
Thank you Turlough, it worked properly.

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 2 月 9 日
You can first writecell the header and then writematrix with WriteMode append.
Or array2table using the labels as variable names and writetable()

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by