How to create parametric table names
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ugur Acar
el 23 de Oct. de 2019
Comentada: Ugur Acar
el 23 de Oct. de 2019
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
Respuesta aceptada
Gustavo Liñán Cembrano
el 23 de Oct. de 2019
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Calendar en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!