Add LOTS of variables into my loop

조회 수: 2 (최근 30일)
C G
C G 2018년 4월 5일
Right now I have the code below. Ultimately I am trying to automate a program using Matlab. I have the batch file needed to run the program. I just need to figure out how to write a CONTROL file that the program needs. The loop below creates 4 control files, but overwrites each one with each iteration. Eventually, the program will run in the loop using the control file before it overwrites it.
The variables I need to change are listed as A-D. These come from the excel file, shown here. The line I am changing is the first line of the CONTROL file and it is just setting the date and hour for the program to start at. The CONTROL file needs to have a bunch of information and this is listed as variable P. The file names listed in P will eventually need to change, but I can work on that later.
What I need to do is expand the loop to include a lot more variables... well over 48000 if I analyze the complete set. But for now, let's go with just one month's worth of data, 125 variables. How do I add these to the loop?
Also if anyone knows how to read in data from ColumnF so that it looks like ColumnF data, i.e. 00 or 06 and not 0 or 6 or even worse "00" or "06", please share. The program needs to have the data as two digits. It doesn't like just one.
filename = 'Book1.xls';
sheet = 1;
xlRange1 = 'c2:f2';
xlRange2 = 'c3:f3';
xlRange3 = 'c4:f4';
xlRange4 = 'c5:f5';
A = xlsread(filename,sheet,xlRange1);
B = xlsread(filename,sheet,xlRange2);
C = xlsread(filename,sheet,xlRange3);
D = xlsread(filename,sheet,xlRange4);
F = {A,B,C,D};
for k = 1:numel(F)
[fid,msg] = fopen(sprintf('CONTROL',k),'wt');
assert(fid>=3,msg)
fprintf(fid,'%2.0f %2.0f %2.0f %2.0f %2.0f %2.0f',F{k}(1:4));
P={'';'3';'-71.166889 111.366531 10.0';'-71.166889 111.366531 2500.0';'-71.166889 111.366531
5000.0';'-240';'0';'30000.0';'5';'C:/hysplit4/MetData/gdas1.dec10.w5';
'C:/hysplit4/MetData/gdas1.dec10.w1';'C:/hysplit4/MetData/gdas1.dec10.w2';'C:/hysplit4/MetData/gdas1.dec10.w3';'C:/hy split4/MetData/gdas1.dec10.w4';
'./tdump10123018';} ;
% fid = fopen('data.txt','wt') ;
fprintf(fid,'%s\n',P{:});
% % % fclose(fid) ;
fclose(fid);
movefile('CONTROL', 'C:\hysplit4\working');
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by