index must be a positive integer or logical. error in matlab

n = 2;
m=2*(n-1)+1;
theta=pi/m;
for i=1:n
y(i) = cos((1-i+(m-1)/2)*theta);
y(i-1)=cos((1-(i-1)+(m-1)/2)*theta); < --- line error
end
How could I rewrite this code to be able to get the y-1 matrix

Answers (1)

You will have to rethink how your y vector is to be indexed. It cannot accept index values of zero which you have used here: when i is equal to 1 you would be indexing y(i-1) as y(0).

1 Comment

I am having trouble rewriting my code to satisfy the conditions i want

This question is closed.

Tags

Asked:

on 2 Mar 2014

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!