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

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.
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..
@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

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.

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 1 Oct 2017

Edited:

on 1 Oct 2017

Community Treasure Hunt

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

Start Hunting!