Each time I write my code I get this error 'Subscript indices must either be real positive integers or logicals.'

3 views (last 30 days)
t = 0:0.05:40; %creating time interval
Omega = 2;
A = 1;
s(t) = (t.^2/4);
y(t) = A * cos(Omega*t + s(t));
subplot(2, 2, 1);
plot(t, y(t))
xlabel('X value');
ylable('y(t)');
title('A chirp signals s(t) = t.^2/4')
%***************************************************************
Omega = 2;
A = 1;
ss(t) = -2*sin(t);
y(t) = A * cos(Omega*t + ss(t));
subplot(2, 2, 2);
plot(t, y(t))
xlabel('X value');
ylable('y(t)');
title('A chirp signals s(t) = -2*sin(t)')
  3 Comments
Ben Sonpon
Ben Sonpon on 1 Oct 2017
I am sorry but all your issue you adder was not the problem, hope the next time your will provide assistance then just making comment that do not provide any help... Thanks..
Stephen23
Stephen23 on 1 Oct 2017
Edited: Stephen23 on 1 Oct 2017
@Ben Sompon: what I told is is exactly the same as what you got told in the answer that you accepted: that non-integer indexing is an error. I also showed you where you use this in your code.

Sign in to comment.

Accepted Answer

OCDER
OCDER on 1 Oct 2017
The issue is you are accessing a matrix using a non-integer index. That's not allowed in MATLAB.
t = 0:0.05:40 %this is not an index
s(t) = (t.^2/4); %matlab cannot access s(0), s(0.05) because index must be integers > 0
y(t) = A * cos(Omega*t + s(t)); %another error
plot(t, y(t)) %another error
To fix this, just do this:
s = (t.^2/4);
y = A * cos(Omega*t + s);
plot(t, y)
There are more errors that you have to fix, but same type of fix.

More Answers (1)

Image Analyst
Image Analyst on 1 Oct 2017

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!