필터 지우기
필터 지우기

How to create parametric table names

조회 수: 1 (최근 30일)
Ugur Acar
Ugur Acar 2019년 10월 23일
댓글: Ugur Acar 2019년 10월 23일
I have a table 59x7 named as 'all_cities'. (Number of rows may change according to avaible data)
I exract the values according to station name. Second column is the station names(Istasyon_Adi).
names_table=all_cities{:,2}; %exract the column where station names are stored
station_names=unique(names_table); % determine the station names one by one
Then, i create unique table containing all other columns/data for each station seperately.
N_station=size(station_names,1); % Number of stations
for i=1:N_station
station_name=station_names(i,1);% determine the station to consider for current loop
station_data=all_cities(all_cities.Istasyon_Adi==station_name,3:7); %create seperate table for considered station
end
But this loop deletes the previous table.
I need to keep all tables created within this loop seperately. Something like this;
N_station=size(station_names,1); % Number of stations
for i=1:N_station
station_name=station_names(i,1);% determine the station to consider for current loop
station_data(i)=all_cities(all_cities.Istasyon_Adi==station_name,3:7); %create seperate table for considered station
end
After that, i need to save the all tables created in the loop with file names which are the same as station name(station_name.xlsx)
N_station=size(station_names,1); % Number of stations
for i=1:N_station
station_name=station_names(i,1);% determine the station to consider for current loop
station_data(i)=all_cities(all_cities.Istasyon_Adi==station_name,3:7); %create seperate table for considered station
writetable(station_data(i),'station_name.xlsx');% write this table to excel file, assign file names as station name considered for this loop
end

채택된 답변

Gustavo Liñán Cembrano
Gustavo Liñán Cembrano 2019년 10월 23일
Have you tried creating a struct for your data?
MyStation=struct('name',[],'data',[]);
for i=1:N_station
MyStation(i).name=station_names(i,1);
MyStation(i).data=all_cities(all_cities.Istasyon_Adi==station_name,3:7);
MyResultFilename=strcat(MyStation(i).name,'.xlsx');
xlswrite(MyResultFilename,MyStation(i).data);
end
then in the struct, in your workspace you have all the information in a single variable MyStation, which has as N_station elements
  댓글 수: 1
Ugur Acar
Ugur Acar 2019년 10월 23일
that seems to work, thank you Gustavo Liñán Cembrano
MyStation=struct('Name',[],'Data',[]);
for i=1:N_station
MyStation(i).Name=station_names(i,1);
MyStation(i).Data=all_cities(all_cities.Istasyon_Adi==MyStation(i).Name,3:7);
MyResultFilename=char(strcat(cellstr(MyStation(i).Name),'.xlsx'));
xlswrite(MyResultFilename,table2array(MyStation(1).Data));
end

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by