How to read two files simultaneously?
조회 수: 3 (최근 30일)
이전 댓글 표시
I have a pair of files such as Arenosillo.2007.047.12.07.G18.txt and Arenosillo.2007.047.12.07.ion.txt. I have such 500 pairs. I have to read data from both the files and plot them. The code I wrote is not working because of two for loops. Can anyone please help? I am working with MATLAB R2015a.
list1=dir('Arenosillo*ion*');
list2=dir('Arenosillo*G*');
for n=1:length(list1)
for i=1:length(list2)
filename1=list1(n).name;
filename2=list2(n).name;
filename_edit=strrep(filename2,'.',';');%make textscan easier
part=textscan(filename_edit,'Arenosillo;%d;%d;%d;%d;%s');
delimiterIn = ' ';
B = importdata(filename2,delimiterIn);
A = importdata(filename1);
Altitude1 = A.data(:,1);
Altitude2 = B(:,1);
Digisonde = B(:,2);
COSMIC = A.data(:,7);
OcculationAz = A.data(:,5);
figure
[hAx,hLine1,hLine2] = plotyy(Altitude1,OcculationAz,[Altitude1',Altitude2'],[COSMIC',Digisonde']);
hLine1.Marker = 'o';
hLine2.Marker = '*';
title('Variation of Electron Density and Occultation Azimuth with Altitude')
xlabel('Altitude (Km)')
ylabel(hAx(1),'Occultation Azimuth (deg)') % left y-axis
ylabel(hAx(2),'Electron Density (/m3)') % right y-axis
legend('Occultation Azimuth','COSMIC','Location','NorthEastOutside')
saveas(gcf,sprintf('Arenosillo.%04d.%03d.%02d.%02d.jpg',part{1},part{2},part{3},part{4}))
end
end
댓글 수: 0
채택된 답변
KSSV
2018년 11월 29일
files = dir('*.txt') ;
N = length(files) ;
for i = 1:N
thisfile = files(i).name ;
% do what you want, load and plot
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Mapping Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!