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

2 ビュー (過去 30 日間)
mohammad mehio
mohammad mehio 2022 年 5 月 15 日
コメント済み: mohammad mehio 2022 年 5 月 16 日
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 件のコメント
Jan
Jan 2022 年 5 月 16 日
@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);
mohammad mehio
mohammad mehio 2022 年 5 月 16 日
yes it worked, thank you so much

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by