필터 지우기
필터 지우기

How to create filename with variable within loop

조회 수: 8 (최근 30일)
Daphne PARLIARI
Daphne PARLIARI 2020년 1월 23일
댓글: Daphne PARLIARI 2020년 1월 23일
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

채택된 답변

Akira Agata
Akira Agata 2020년 1월 23일
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' }

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by