save work space variables into excel sheet headlines and columns

조회 수: 2 (최근 30일)
amjad almaarafawi
amjad almaarafawi 2019년 12월 14일
답변: Voss 2024년 1월 2일
Hi, I have a lone code with about 7 variables Im trying to save into excel sheet with the variables names as headline and the data into the column of that headline. all the varables are matrix 20x1 and the names are listed below.
r_coords
extracted_data
r_exper
V_exper
V_interpolation
Absuolut_Error
Relative_Error
filename = (sprintf('monitor_line_%d_ degree %.1fCA_%s', Monitor_line, CrankAngle, upper(variable)));
Results_Names={'r_coords','extracted_data','r_exper','V_exper','V_interpolation','Absuolut_Error','Relative_Error'};
Results_Values=[r_coords,extracted_data,r_exper,V_exper,V_interpolation,Absuolut_Error,Relative_Error];
sheet=1;
xlswrite('filename.xlsx',Results_Values,sheet);

답변 (1개)

Voss
Voss 2024년 1월 2일
One way to write the file:
C = [Results_Names; num2cell(Results_Values)];
writecell(C,filename)
Another way to write the file:
T = array2table(Results_Values,'VariableNames',Results_Names);
writetable(T,filename)
Another (not recommended) way to write the file:
sheet=1;
C = [Results_Names; num2cell(Results_Values)]
xlswrite(filename,C,sheet);

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by