필터 지우기
필터 지우기

How to include similar text files into a loop

조회 수: 1 (최근 30일)
Binu
Binu 2016년 5월 19일
답변: Binu 2016년 5월 19일
I have 25 text files that include heights data from year 1991 to 2015. Each file contains only one column of data ( eg 40, 50, 120, 20, 62, 75, 15, 13, 25, 24…..) but the length of data in each file is different. The files are named like HGT1991, HGT1992…HGT2015. For each file, I need to find the number of data points that go below 40. How can I do this in a loop rather than doing the same thing for individual files for 25 times? And also I need to plot the data for each year. How I can call the file name as the title? Any help is appreciated.

채택된 답변

KSSV
KSSV 2016년 5월 19일
txtfiles = dir('*.txt'); % You are in the directory of text files
Nfiles = length(txtfiles) ; % number of text files
% loop for each file
for i = 1:Nfiles
fname = txtfiles(i).name ; % file name
data = importdata(fname) ; % import data from file
%%do what you want %%%
end

추가 답변 (1개)

Binu
Binu 2016년 5월 19일
It worked really well. Thanks Siva

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by