How to read two files simultaneously?

5 次查看(过去 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

采纳的回答

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

更多回答(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