title: Matlab cell length
body: <p>Ok I seem to have got the most of the problem solved, I just need an expert eye to pick my error as I am stuck.</p>
  
  <p>I have a file of length <code>[125 X 27]</code> and I want to convert it to a file of length <code>[144 x 27]</code>.  Now, I want to replace the missing files (time stamps) rows of  zeros. (ideally its a 10 min daily average thus should have file length of 144)</p>
  
  <p>Here is the code I am using:</p>
  
  <pre><code>fid = fopen('test.csv', 'rt');
  
  data = textscan(fid, ['%s' repmat('%f',1,27)], 'HeaderLines', 1, 'Delimiter', ',');
  
  fclose(fid);
  
  %//Make time a datenum of the first column
  time = datenum(data{1} , 'mm/dd/yyyy HH:MM')
  %//Find the difference in minutes from each row
  
  timeDiff = round(diff(datenum(time)*(24*60)))
  
  %//the rest of the data
  data = cell2mat(data(2:28));
  
  
  newdata=zeros(144,27);
  
  for n=1:length(timeDiff)
  
      if timeDiff(n)==10
  
          newdata(n,:)=data(n,:);
          newdata(n+1,:)=data(n+1,:);
      else
          p=timeDiff(n)/10
          n=n+p;
  
      end
  
  end
  </code></pre>
  
  <p>Can somebody please help me to find the error inside my <code>for</code> loop. My output file seems to miss few timestamped values.</p>
  
  <p>%*************************************************************************************************************************************************************************************</p>
  
  <p>Can somebody help me to figure out the uiget to read the above file??</p>
  
  <p>i am replacing</p>
  
  <blockquote>
    <p>fid = fopen('test.csv', 'rt');</p>
    
    <p>data = textscan(fid, ['%s' repmat('%f',1,27)], 'HeaderLines', 1, 'Delimiter', ',');</p>
    
    <p>fclose(fid);</p>
  </blockquote>
  
  <p>With</p>
  
  <blockquote>
    <p>[c,pathc]=uigetfile({'*.txt'},'Select the file','C:\data');</p>
    
    <p>file=[pathc c];</p>
    
    <p>file= textscan(c, ['%s' repmat('%f',1,27)], 'HeaderLines', 1, 'Delimiter', ',');</p>
  </blockquote>
  
  <p>And its not working</p>
  
  <p>%</p>
  
  <hr>
  
  <p>NEW ADDITION to old question</p>
  
  <blockquote>
    <p>p = 1; %index into destination<br>
    for n = 1:length(timeDiff)<br>
    %     if timeDiff(n) == 10<br>
    %         newfile(p,:) = file(n,:);<br>
    %          newfile(p+1,:)=file(n+1,:);<br>
    %         p = p + 1;<br>
    %     else<br>
    %         p = p + (timeDiff(n)/10);<br>
    %     end    </p>
    
    <p>q=cumsum(timeDiff(n)/10);<br>
    if q==1<br>
    newfile(p,:)=file(n,:);<br>
    p=p+1;<br>
      else<br>
          p = p + (timeDiff(n)/10);   </p>
    
    <p>end   </p>
    
    <p>end    </p>
    
    <p>xlswrite('testnewws11.xls',newfile);   </p>
  </blockquote>
  
  <p>even with the cumsum command this code fails when my file has  1,2 time stamps in middle of  long missing ones
  example   </p>
  
  <blockquote>
    <p>8/16/2009 0:00 5.34<br>
    8/16/2009 0:10 3.23<br>
    8/16/2009 0:20 2.23<br>
    8/16/2009 0:30 1.23<br>
    8/16/2009 0:50 70<br>
    8/16/2009 2:00 5.23<br>
    8/16/2009 2:20 544<br>
    8/16/2009 2:30 42.23<br>
    8/16/2009 3:00 71.23<br>
    8/16/2009 3:10 3.23  </p>
  </blockquote>
  
  <p>My output looks like   </p>
  
  <blockquote>
    <p>5.34<br>
    3.23<br>
    2.23<br>
    0<br>
    0<br>
    0<br>
    0<br>
    0<br>
    0<br>
    0<br>
    0<br>
    0<br>
    5.23<br>
    544.<br>
    42.23<br>
    0<br>
    0<br>
    0<br>
    3.23</p>
  </blockquote>
  
  <p>Any ideas?</p>