Index in position 1 exceeds bounds
6 views (last 30 days)
Show older comments
I don't exactly see what I am doing wrong on or missing in index. But setting up the Date array probably off.
Thanks
Marv.
ERROR
Index in position 1 exceeds array bounds.
Error in Data_Analyzer (line 47)
Date{1,6} = str2num(Date{1,6})/1000;
CODE ...
clear clear all();
directory1 = pwd;
Folder1 = '\TDMS Read';
Folder2 = '\Figures';
Folder3 = '\Reports';
directory2 = sprintf('%s%s',directory1,Folder1);
directory3 = sprintf('%s%s',directory1,Folder2);
directory4 = sprintf('%s%s',directory1,Folder3);
cd(directory2);
TDMS = TDMS_readTDMSFile('C:\Users\e422425\Documents\MATLAB\TDMSData\TDMS Read\Practice_Data2.tdms');
DataSize = size(TDMS.data,2);
DataSize = 23
filename = 'Max_Min_Mean.xlsx';
cd(directory1);
header = {'Sensor Designator','Max','Min'};
ChanExtrData = cell(DataSize + 1,3);
ChanExtrData(1,:) = header;
%%First Motion Circuit
N = 23;
z1 = 0;
y = TDMS.data(1,N);
%Get Channel Name
c = TDMS.dataType(1,N);
if c == 10
%Channel Information is pulled from x.propertyValues from this we derive
%the individual channels start time and time differential/sample rate
y = cell2mat(y);
z = TDMS.propValues(1,N);
z1 = z1+1;
NameArray = TDMS.chanNames(1,1);
ChanName = NameArray{1}{1,z1};
TimeStamp = z{1}{1,26};
TimeDiff = z{1}{1,24};
[ThrowAway,First_Motion_Index] = size(y);
Date = regexp(TimeStamp,'\d*','Match');
Date{1,6} = str2num(Date{1,6})/1000;
Date{1,5} = str2num(Date{1,5});
0 Comments
Answers (1)
Voss
on 21 May 2024
Edited: Voss
on 21 May 2024
Check the value of TimeStamp and figure out why it's not what you expect, because regexp doesn't return any matches for that TimeStamp. Example:
TimeStamp = 'kljsdfh';
Date = regexp(TimeStamp,'\d*','Match')
try
Date{1,6}
catch e
e.message
end
If there were at least one match but fewer than 6 matches, you'd get a different error. Example:
TimeStamp = 'kljs55dfh';
Date = regexp(TimeStamp,'\d*','Match')
try
Date{1,6}
catch e
e.message
end
2 Comments
Voss
on 22 May 2024
Edited: Voss
on 22 May 2024
You're welcome!
You may want to set a breakpoint or use dbstop if error in order to check the value of TimeStamp just before the error happens.
See Also
Categories
Find more on Time Series Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!