Index in position 2 exceeds array bounds (must not exceed 1). Error in cut1 (line 2) y=X(:,a:b);

1 view (last 30 days)
when I run the main code I got this problem
close all; clear all; clc;
for i = 1:7
test=load ((['TBGEMGPATIENT',num2str(i),'.txt']))';
fig1=figure;plot(test);
title ('original signal');
xlabel ('time (sec)');
ylabel ('Amplitute (V)');
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-mean(y1);
y1 = detrend(y1);
N = length(y1);% find the length of the data per second
ls = size(y1); %% size
f = 1/N;% find the sampling rate or frequency
fs = 1000;
T = 1/fs; % period between each sample
t1 = (0 : N-1) *T;%t = (0:1:length(y1)-1)/fs; % sampling period
Nyquist = fs/2;
figure;
end
%this is the code for cut1:
function y=cut(X,a,b)
y=X(:,a:b);
end
what should I do for y = X(:,a:b)? because when I added for end I start to have this problem
  7 Comments
Jan
Jan on 16 May 2022
@mohammad mehio: The idea of "class(test), size(test)" is, to show the readers, what the type and size of the array is. Of course this does not fix the problem, but it helps you to post the relevant details here.
So please follow Torsten's instructions:
% insert
class(test)
size(test)
% What do you get as output ?
I guess, that test is a column vector of the size [N x 1] and you try to cut it along the 2nd dimension.
If so, use:
y = X(a:b);

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!