Each time I write my code I get this error 'Subscript indices must either be real positive integers or logicals.'
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
Your indexing make no sense, and you do not show/explain what s is supposed to be. Indexing, as that error message clearly states, must be positive integer values only. Now have a look at your code:
t = 0:0.05:40;
...
s(t) = ...
Does t have positive integer values or logical values? No, it has fractional values. Therefore using t as indices into s is an error.
How did you manage to write more than ten lines of code, when the fourth line does not work? Write and test every line as you write it. Do not move on to the next line until you are sure that it does exactly what you need it to do.
Ben Sonpon
on 1 Oct 2017
Accepted Answer
More Answers (1)
Image Analyst
on 1 Oct 2017
0 votes
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
Categories
Find more on Programming 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!