How to create parametric table names

2 次查看(过去 30 天)
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
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