Itterate over array in steps of 120.
    5 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
Hi guys, I am trying to figure out how I can itterate over 16800 rows in steps of 120. I.e. I want to loop over the first 120 rows and then loop over the next 120 rows etc. . Currently, the script only loops the first 120 rows, but I cannot get it to itterate over al the other rows in loops of 120. Is there anybody who can help me out? Thanks a lot in advance!!!
r=readmatrix('data_jong_edit.txt');
r(isnan(r(:,1)),:)=[];
empty = nan(16800,2);
r = [r empty];
u=unique(r(:,1));
count1 = 0;
count2 = 0;
    for k=1:120
        if r(k,9) == 1 
                count1 = count1 + 1;
                count2 = count2 + 1;
                r(k,12) = count1;
                r(k,13) = count2;
         elseif r(k,9) == -1
                count1 = count1;
                count2 = count2 + 1;
                r(k,12) = count1;
                r(k,13) = count2;
        elseif r(k,9) == 9999
                count1 = count1;
                count2 = count2;
                r(k,12) = count1;
                r(k,13) = count2;
        end 
    end 
Risposta accettata
  Torsten
      
      
 il 15 Giu 2022
        
      Modificato: Torsten
      
      
 il 15 Giu 2022
  
      r=readmatrix('data_jong_edit.txt');
r(isnan(r(:,1)),:)=[];
empty = nan(16800,2);
r = [r empty];
u=unique(r(:,1));
for k=1:size(r,1)
    if mod(k,120) == 1
        count1 = 0;
        count2 = 0;
    end
    if r(k,9) == 1 
        count1 = count1 + 1;
        count2 = count2 + 1;
        r(k,12) = count1;
        r(k,13) = count2;
    elseif r(k,9) == -1
        count1 = count1;
        count2 = count2 + 1;
        r(k,12) = count1;
        r(k,13) = count2;
    elseif r(k,9) == 9999
        count1 = count1;
        count2 = count2;
        r(k,12) = count1;
        r(k,13) = count2;
    end 
end 
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

