How to deal with Index exceeds the number of array elements ?
3 次查看(过去 30 天)
显示 更早的评论
Hi all,
I have a signal like this (also attached).
I want to extract signal between first start and first end, second start and second end and so on. I am doing this like this:
load 'signal'
start_location = [147,222,302,379,458,538,620,698,777];
start_value = [-81.905,-87.408,-86.262,-85.463,-85.893,-84.910,-84.614,-83.543,-84.500]
end_location = [200,275,352,431,511,593,674,762];
end_value = [-85.369,-85.028,-82.240,-80.933,-80.943,-80.082,-83.108,-85.543];
plot(thigh_orient_y,'k')
hold on
plot(start_location,start_value,'ro')
plot(end_location,end_value,'g*')
h = legend('signal','start', 'end');
%Settings
a = start_location ;
b = end_location;
n = length(a);
%Extract data between red and green indices and put in cells
T_or_y_cycle = cell(n,1) ;
for i = 1:n
T_or_y_cycle{i} = thigh_orient_y(a(i):b(i)) ;
end
I am getting error
Index exceeds the number of array elements
Beacuse there is larger number of 'start' than 'end', as the signal is cut at the end. Can you please help how to deal with this?
The n cannot be lenght(b) beacuse the signal can be cut at the begging and start with 'end' like here:
2 个评论
采纳的回答
Ankit
2022-1-31
load 'signal'
start_location = [147,222,302,379,458,538,620,698,777];
start_value = [-81.905,-87.408,-86.262,-85.463,-85.893,-84.910,-84.614,-83.543,-84.500]
end_location = [200,275,352,431,511,593,674,762];
end_value = [-85.369,-85.028,-82.240,-80.933,-80.943,-80.082,-83.108,-85.543];
plot(thigh_orient_y,'k')
hold on
plot(start_location,start_value,'ro')
plot(end_location,end_value,'g*')
h = legend('signal','start', 'end');
%Settings
a = start_location ;
b = end_location;
n = min(length(a),length(b)); % this will avoid extra start or end value.
%Extract data between red and green indices and put in cells
T_or_y_cycle = cell(n,1) ;
for i = 1:n
T_or_y_cycle{i} = thigh_orient_y(a(i):b(i)) ;
end
0 个评论
更多回答(1 个)
KSSV
2022-1-31
Your start_location is of size 1x9. Where as end_location is only 1x8. You need to put one more index in the variable end_location.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Vibration Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!