Borrar filtros
Borrar filtros

Problem with error "Subscript indices must either be real positive integers or logicals"

2 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Adam
Adam el 1 de Mayo de 2018
Use
Y = y( round( Ty ) );
to ensure they are actually integers. at least one of them must have decimal values, however small.
  3 comentarios
Adam
Adam el 2 de Mayo de 2018
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.
Krithika A
Krithika A el 3 de Mayo de 2018
Oh. I understand. I'll need to keep that in mind. Thank you.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by