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 Center および File ExchangeMapping Toolbox についてさらに検索

製品


リリース

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by