2

I'm new to matlab, and in this academic exercise they asked us to do a sampling from a continuous function.

My original functions are:

x = sin(pi * t);
y = cos(2 * pi * t / 3);
z = x + y - 2;

In the interval

t = -8:0.001:8;

Then they asked us to make a sampling, z(n), of z with a period of Ts=0.01 seconds.

My idea was to save in a new vector the values of z, jumping through z ten by ten positions:

n = numel(z);
Zd = z(0:10:z);

This idea came from the fact that 0.01 seconds is ten times less accurate then the first 'continuous' interval t. But matlab says that this is not possible and gives me the error:

??? Subscript indices must either be real positive integers or logicals.

Can somebody give me some hint on this?

3
  • 5
    MATLAB index starts from 1 not 0. Commented Mar 8, 2013 at 3:04
  • 1
    OMG ! I just 'wasted' a question on SO with this. Shame on me. Thanks! Commented Mar 8, 2013 at 3:06
  • Also see this question for the generic solution to this problem. Commented Nov 27, 2013 at 16:11

1 Answer 1

2

As 2 @Memming said, matlab indexes start at 1 and not 0, and that was my problem.

Thanks.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.