Index in position 1 exceeds bounds

1 次查看(过去 30 天)
Marvin Magill
Marvin Magill 2024-5-21
编辑: Voss 2024-5-22
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});

回答(1 个)

Voss
Voss 2024-5-21
编辑:Voss 2024-5-21
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')
Date = 0x0 empty cell array
try
Date{1,6}
catch e
e.message
end
ans = 'Index in position 1 exceeds array bounds.'
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')
Date = 1x1 cell array
{'55'}
try
Date{1,6}
catch e
e.message
end
ans = 'Index in position 2 exceeds array bounds. Index must not exceed 1.'
  2 个评论
Marvin Magill
Marvin Magill 2024-5-22
I like the try catch troubleshooting. Never used that.
So seems like the problem is the Date array size, just not being big enough so suppose I need to figure out how the "regexp: is deifning it. Date(1,6) doesn't work but Date(1,1) does. Will go back and review the syntax on this I guess probably something obvious just not at moment.
Thanks
Voss
Voss 2024-5-22
编辑:Voss 2024-5-22
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Downloads 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by