How to read two files simultaneously?

조회 수: 3 (최근 30일)
SGMukherjee
SGMukherjee 2018년 11월 29일
댓글: SGMukherjee 2018년 11월 29일
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

채택된 답변

KSSV
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
  댓글 수: 1
SGMukherjee
SGMukherjee 2018년 11월 29일
This worked. Thank you so much.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mapping Toolbox에 대해 자세히 알아보기

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by