Assign names to excel sheets with respet to the original filenames?

조회 수: 1 (최근 30일)
Daphne PARLIARI . 2020년 3월 19일
댓글: Ameer Hamza . 2020년 3월 20일
Hello. I hope everyone is safe and healthy during these hard times.
I have the codes lines below which help me combine 8 different .xlsx into one, in different sheets. Attached you can find one of the 8, as an example. I want now to assign names each excel sheet according to the name of the weather station the data came from, in order to keep track easily. Eg., for the attached .xlsx the respective sheet name should be "Airport".
Could anyone help me? Thank you in advance!
filenames = {'C:\PhD\Projects\LIFE ASTI\C.3\WRF_main_TS_2015_ALL\WRF_Times_ALB+EMISS_FINAL2015\WRF_Thessaloniki_stations_2015\Evaluation_Output_2015(1st layer)\Airport\Monthly RH stats Airport 2015.xlsx','C:\PhD\Projects\LIFE ASTI\C.3\WRF_main_TS_2015_ALL\WRF_Times_ALB+EMISS_FINAL2015\WRF_Thessaloniki_stations_2015\Evaluation_Output_2015(1st layer)\Eptapurgio\Monthly RH stats Eptapurgio 2015.xlsx',...
'C:\PhD\Projects\LIFE ASTI\C.3\WRF_main_TS_2015_ALL\WRF_Times_ALB+EMISS_FINAL2015\WRF_Thessaloniki_stations_2015\Evaluation_Output_2015(1st layer)\Malakopi\Monthly RH stats Malakopi 2015.xlsx',...
'C:\PhD\Projects\LIFE ASTI\C.3\WRF_main_TS_2015_ALL\WRF_Times_ALB+EMISS_FINAL2015\WRF_Thessaloniki_stations_2015\Evaluation_Output_2015(1st layer)\Martiou\Monthly RH stats Martiou 2015.xlsx', 'C:\PhD\Projects\LIFE ASTI\C.3\WRF_main_TS_2015_ALL\WRF_Times_ALB+EMISS_FINAL2015\WRF_Thessaloniki_stations_2015\Evaluation_Output_2015(1st layer)\Paparrigopoulou\Monthly RH stats Paparrigopoulou 2015.xlsx',...
'C:\PhD\Projects\LIFE ASTI\C.3\WRF_main_TS_2015_ALL\WRF_Times_ALB+EMISS_FINAL2015\WRF_Thessaloniki_stations_2015\Evaluation_Output_2015(1st layer)\Parko\Monthly RH stats Parko 2015.xlsx', 'C:\PhD\Projects\LIFE ASTI\C.3\WRF_main_TS_2015_ALL\WRF_Times_ALB+EMISS_FINAL2015\WRF_Thessaloniki_stations_2015\Evaluation_Output_2015(1st layer)\Pedio Arews\Monthly RH stats Pedio Arews 2015.xlsx',...
'C:\PhD\Projects\LIFE ASTI\C.3\WRF_main_TS_2015_ALL\WRF_Times_ALB+EMISS_FINAL2015\WRF_Thessaloniki_stations_2015\Evaluation_Output_2015(1st layer)\Rooftop Zanis\Monthly RH stats Rooftop Zanis 2015.xlsx'};
outfile = [output_path,'\','Monthly RH stats All stations 2015.xlsx'];
for fidx = 1:numel(filenames),
fTable = readtable(filenames{fidx});

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 3월 19일
편집: Ameer Hamza 님. 2020년 3월 20일
You can also specify the name of the sheet to the writetable function instead of the sheet number.
First extract the name of weather station from filenames
[names, ~] = regexp(filenames, 'stats\s([\sa-zA-Z]*)\s2015\.xlsx', 'tokens', 'match');
names = string(names);
This regular expression will work as long as the filename end with 2015.xlsx. Then use these names in writetables
for fidx = 1:numel(filenames),
fTable = readtable(filenames{fidx});
  댓글 수: 9
Ameer Hamza
Ameer Hamza 2020년 3월 20일
Stephen, thanks for pointing out. I was a bit sloppy there.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)


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

Community Treasure Hunt

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

Start Hunting!

Translated by