How to create filename with variable within loop

5 vues (au cours des 30 derniers jours)
Daphne PARLIARI
Daphne PARLIARI le 23 Jan 2020
Commenté : Daphne PARLIARI le 23 Jan 2020
Good morning guys!
My task is to create filenames that correspond to some weather stations I have in my hands. I am attaching a .txt with stations' names. Want I want to have in the end are filenames like that:
Hourly Data Airport 2015.txt
Hourly Data Eptapurgio 2015 txt.
and so on. Obviously I am doing it wrong... Could you please take a look at my code (several lines are missing because it's long enough) ang guide me to a solution? Thanks in advance!
for i=1:size(stations,1)
name = stations( i, 1 );
network = stations (i, 'Network');
network.(1);
name.(1);
networkstr = char(network.(1));
namestr = char(name.(1));
indx = strfind (list1, namestr) ;
for j = 1:size(indx, 1)
if (indx{j,1}>0)
if (strfind (list1{j,1}, '2015') > 0)
if (strfind(list1{j,1}, 'xlsx') > 0)
for m=1:size(vars,1)
if(~exist([output_path,'\',namestr,'\',strrep(vars{m},' ','_'),'\'],'dir'))
mkdir([output_path,'\',namestr,'\',strrep(vars{m},' ','_')])
end
end
fname = (output_path,'\',namestr,'\', 'Hourly Data ' ,strrep(stations(i,1), '2015.txt');
writetable(Hourly_Data,fname);
end

Réponse acceptée

Akira Agata
Akira Agata le 23 Jan 2020
How about the following?
T = readtable('Stations coordinates.txt');
fileName = append('Hourly Data ',T.Station,' 2015.txt');
>> fileName
fileName =
16×1 cell array
{'Hourly Data Airport 2015.txt' }
{'Hourly Data Eptapurgio 2015.txt' }
{'Hourly Data Martiou 2015.txt' }
{'Hourly Data Lagada 2015.txt' }
{'Hourly Data Malakopi 2015.txt' }
{'Hourly Data Egnatia 2015.txt' }
{'Hourly Data Dimarxeio 2015.txt' }
{'Hourly Data Pedio Arews 2015.txt' }
{'Hourly Data Paparrigopoulou 2015.txt' }
{'Hourly Data Parko 2015.txt' }
{'Hourly Data Taratsa 2015.txt' }
{'Hourly Data Taratsa Babzelis 2015.txt'}
{'Hourly Data Taratsa Zanis 2015.txt' }
{'Hourly Data Kalamaria 2015.txt' }
{'Hourly Data Panorama 2015.txt' }
{'Hourly Data Kordelio 2015.txt' }

Plus de réponses (0)

Catégories

En savoir plus sur Text Data Preparation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by