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)
Show older comments
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
Accepted Answer
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.
0 Comments
More Answers (1)
Image Analyst
on 1 Oct 2017
For a full discussion, see the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_fix_the_error_.22Subscript_indices_must_either_be_real_positive_integers_or_logicals..22.3F
0 Comments
See Also
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!