How to read two files simultaneously?

4 visualizaciones (últimos 30 días)
SGMukherjee
SGMukherjee el 29 de Nov. de 2018
Comentada: SGMukherjee el 29 de Nov. de 2018
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

Respuesta aceptada

KSSV
KSSV el 29 de Nov. de 2018
files = dir('*.txt') ;
N = length(files) ;
for i = 1:N
thisfile = files(i).name ;
% do what you want, load and plot
end

Más respuestas (0)

Etiquetas

Productos


Versión

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by