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

Generating multiple text files with dlmwrite

$
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/column two - hour since the initial time.

The files that are 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).

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];
layers = [50 55 63 70 74 77 84 89 96 97];
A = dir('merge*.txt');
Jout = zeros(1000000, 10);
vals = cell(1,length(A));
for i = 1:length(A);
    vals{i} = load(A(i).name);
    for k = 1:C
        B = find(vals{i}(:,5) == days(k));
        D(k) = length(B);
        E = repmat(hrs(k), [D(k) 1]);
        F = vals{i}(B,6);
        G = E + F;
        H = vals{i}(B,5);
        J = horzcat(H, G);
        
     end
    
        Jout(i) = vertcat(J(i));
        hours_files = ['p_test_' num2str(layers(i)) '.txt'];
        dlmwrite(hours_files, Jout(i), 'delimiter', '\t');

end

Viewing all articles
Browse latest Browse all 55

Trending Articles