Index in position 2 exceeds array bounds (must not exceed 1).

조회 수: 10 (최근 30일)
mohammad mehio
mohammad mehio 2022년 5월 14일
댓글: Voss 2022년 5월 14일
I have txt file which is EMG signal
when I running it it gives me error from function called cut1
I give a and b
give me the value of a: 100
give me the value of b: 10000
this is the error
Index in position 2 exceeds array bounds (must not exceed 1).
Error in cut1 (line 2)
y=X(:,a:b);
below is cut1 function
function y=cut1(X,a,b)
y=X(:,a:b);
end
below is the main code
close all; clear all; clc;
for i= 1:7
eq1 = load ((['TBGEMGPATIENT',num2str(i),'.txt']))';
test=eq1;
fig1=figure;plot(test)
title ('original signal');
xlabel ('time (sec)');
ylabel ('Amplitute (V)');
% dcm_obj = datacursormode(fig1);
% set(dcm_obj,'DisplayStyle','datatip',...
% 'SnapToDataVertex','off','Enable','on')
% a1= getCursorInfo(dcm_obj)
a= input('give me the value of a: ');
b= input('give me the value of b: ');
z=cut1(test,a,b);
signal=z;
s=size(signal);
b=s(1)*s(2);
x=reshape(signal,[1,b]);
y1=x';
% y1=y1(2000:8000,:);
y1=y1-mean(y1);
end
  댓글 수: 2
Torsten
Torsten 2022년 5월 14일
편집: Torsten 2022년 5월 14일
"test" seems to be a column vector. So it makes no sense to reference
test(:,100:10000)
in function "cut1".
mohammad mehio
mohammad mehio 2022년 5월 14일
when I removed for and remove num2str
it worked normally

댓글을 달려면 로그인하십시오.

답변 (1개)

Voss
Voss 2022년 5월 14일
"Index in position 2 exceeds array bounds (must not exceed 1)."
This error message means the code is trying to access a column ("Index in position 2") that doesn't exist in that variable ("exceeds array bounds") because the variable has one column ("(must not exceed 1)").
The variable is X in this case, and you've told us that a is 100 and b is 10000. So X(:,a:b) is the 100th through 10000th columns of X. But the error says X has only one column.
The solution might be to change X so that it has at least 10000 columns, or the solution might be to change the indexing to access the 100th through 10000th elements of X, i.e., X(a:b)
  댓글 수: 2
mohammad mehio
mohammad mehio 2022년 5월 14일
when I removed for and remove num2str
it worked normally
Voss
Voss 2022년 5월 14일
So now it's like this?
eq1 = load('TBGEMGPATIENT.txt')';
That's a different file than was used before. Maybe that file has 10000 columns instead of 1.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by