Quantcast
Channel: MATLAB Central Newsreader - tag:"find"
Viewing all articles
Browse latest Browse all 55

Generating multiple text file with

$
0
0
Hello
The goal of the script below is to generate files p_test_50.txt...p_test_97.txt that contain 2 columns of data. Column one - day of month and column two - number of hours since the initial time.

The files read (merge*.txt) contain dates of the month (28:30) and hours 0 to 23 . However I need hours since the initial time (00 UTC on the 28th) for each of the layers (50...97). I add 24, 48, 72 to the hours within each day respectively.

Empty p_test_50.txt...p_test_97.txt are generated in the current script. Each file should vary in size and the columns within them should contain varying number of rows of information. Please help. Thanks

 
clear

J = cell(1000000,2);
days = 28:30;
C = length(days);
D = zeros(1000000,1);
hrs = [0 24 48 72];
L = length(hrs);
layers = [50 55 63 70 74 77 84 89 96 97];
A = dir('merge*.txt');
P = length(A);
Jout = cell(1000000, 10);
vals = cell(1,length(A));

for n = 1:P
    vals{n} = load(A(n).name);
        for k = 1:C
            B = find(vals{n}(:,5) == days(k));
            D(n) = length(B);
            
             for m = 1:L
                E = repmat(hrs(m), [D(n) 1]);
             end

        end
     F = vals{n}(B,6);
     G = E + F;
     H = vals{n}(B,5);
     J{n} = horzcat(H, G);
     Jout{n} = vertcat(J{n});
     hours_files = ['p_test_' num2str(layers(n)) '.txt'];
     dlmwrite(hours_files, Jout{n}, 'delimiter', '\t');

end

Viewing all articles
Browse latest Browse all 55

Trending Articles