Problem with error "Subscript indices must either be real positive integers or logicals"
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I know this is a common problem, but I don't know how to fix it in my own context. I get the following error on line 20 (Y = y(Ty)): "Subscript indices must either be real positive integers or logicals". I don't think I'm using an in-built function, and I checked Ty and y to see if there are any 0s, but there are none. I find it really strange as the code for "y" is the same as "x", but I'm only getting this error with "y". I am using Matlab R2017a.
My code:
clear all
close all
x = rand(1,38400);
fs = 128;
t = (0:length(x)-1)/fs;
ST = 10*fs;
EN = 60*fs;
T = t(ST:EN);
Tx = T*fs;
X = x(Tx);
y = rand(1,75000);
fs1 = 250;
t1 = (0:length(y)-1)/fs1;
ST1 = 10*fs1;
EN1 = 60*fs1;
T1 = t1(ST1:EN1);
Ty = T1*fs1;
Y = y(Ty); %Line 20
newyfs = fs1/fs;
ny = Y(1:newyfs:end);
nt = T1(1:newyfs:end);
nfs1 = fs1/newyfs;
[acor,lag] = xcorr(ny,X,'coef');
[~,I] = max(abs(acor));
timeDiff = lag(I);
figure
subplot(311); plot(Tx,X); title('X');
subplot(312); plot(nt,ny); title('Y');
subplot(313); plot(lag/nfs1,acor);
title('Cross-correlation')
I am practising this code so I can apply it to my data, where I want to check the correlation of two signals from the same source but each signal is recorded from different systems.
댓글 수: 0
채택된 답변
Adam
2018년 5월 1일
Use
Y = y( round( Ty ) );
to ensure they are actually integers. at least one of them must have decimal values, however small.
댓글 수: 3
Adam
2018년 5월 2일
isinteger tests whether the data is of integer type, not whether the variable is integer valued. Anything that is the result of maths involving operations more complicated than addition and subtraction may result in data that is not quite integer valued though, even if you start with integers and the exact analytic result should be an integer - it's just the way floating point maths works on a computer.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Transforms에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!