Hello!
I am trying to code something in Matlab and it involves a lot of accessing elements in vectors. Below is a snippet of code that I am working on:
x(1)=1;
for i=2:18
x(i)=0;
end
for i=1:18
y(i)=1;
end
for i = 0:262124
x(i+18+1) = x(i+7+1) + mod(x(i+1),2);
y(i+18+1) = y(i+10+1) + y(i+7+1) + y(i+5+1) + mod(y(i+1), 2);
end
n = 2;
for i = 0: 262142
z(i+1) = x(mod(i+n+1, 262143));
end
In the last "for" loop where I am initialising vector z(), I get an error saying: "Subscript indices must either be real positive integers or logicals." However, when I do not suppres z(i+1) by ommiting the semi colon, the program is able to run, and I can see the values of z in the workspace. Why is this?
The code I am writing in Matlab is based upon the series of instructions shown in the image below. However, I can't seem to track down my error which leads to me not being able to access the elements of x() (without not suppressing the output of z()).
I appreciate any guidance. Thank you!
1 Comment
Direct link to this comment
https://nl.mathworks.com/matlabcentral/answers/648278-error-when-accessing-indices-of-a-vector#comment_1134348
Direct link to this comment
https://nl.mathworks.com/matlabcentral/answers/648278-error-when-accessing-indices-of-a-vector#comment_1134348
Sign in to comment.