필터 지우기
필터 지우기

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