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

8 visualizzazioni (ultimi 30 giorni)
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 Commenti
Torsten
Torsten il 14 Mag 2022
Modificato: Torsten il 14 Mag 2022
"test" seems to be a column vector. So it makes no sense to reference
test(:,100:10000)
in function "cut1".
mohammad mehio
mohammad mehio il 14 Mag 2022
when I removed for and remove num2str
it worked normally

Accedi per commentare.

Risposte (1)

Voss
Voss il 14 Mag 2022
"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 Commenti
mohammad mehio
mohammad mehio il 14 Mag 2022
when I removed for and remove num2str
it worked normally
Voss
Voss il 14 Mag 2022
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.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by