Index exceeds Matrix Dimension
    3 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
I'm following a comparatively larger code and I'm stuck in this section.
T1=num2str(TTime);
if length(T1)==9
     T1=['0',T1];
end
T11=datenum([str2double(T1(1,1:4)) str2double(T1(1,5:6)) str2double(T1(1,7:8)) str2double(T1(1,9:10)) str2double(T1(1,11:12)) str2double(T1(1,13:14))]);
Here, TTime is an array of numbers that specifies a date/time. (Ex: 20140705001529. i.e. year,month,date,hour,minutes,second) But I keep getting the error "Index exceeds matrix dimensions." Initially, str2double was replaced with str2num.
I know this snippet might not be enough to figure things out but any help from you guys is appreciated! If you have any suggestions, please do let me know.
Thanks in advance.
6 commentaires
  Adam
      
      
 le 11 Déc 2019
				You should be able to find out why you are getting the error trivially using the Pause on Errors option from the Run menu.  It will stop the code at the line of the error.  Then you can simply look at the relevant components in the workspace or on command line.  How to fix it is another matter, but simply to know what the cause is should be very simple.
Réponses (1)
  Stephen23
      
      
 le 11 Déc 2019
        
      Modifié(e) : Stephen23
      
      
 le 11 Déc 2019
  
      Simpler, more robust code:
>> N = 20140705001529; % Ugh... dates should not be stored like this!
>> S = sprintf('%d',N);
>> S(end+1:14) = '0'; % ensure 14 digits
>> T = datenum(S,'yyyymmddHHMMSS')
T =
     7.357850107523148e+05
Checking:
>> datevec(T)
ans =
        2014           7           5           0          15          29
Or even better using datetime:
>> T = datetime(S,'InputFormat','yyyyMMddHHmmss')
T = 
   05-Jul-2014 00:15:29
5 commentaires
Voir également
Catégories
				En savoir plus sur Time Series Objects dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



