matlab Subscript indices must either be real positive integers or logicals错误

问题描述:

matlab Subscript indices must either be real positive integers or logicals错误
a=[1,2,3,4,5,6,7,8,9,10];
for i=1:length(a)/2
b(i)=a(2i);
end
以上举个例子,实际向量要长得多,就是把原向量a每隔一个数取一个数再组成一个长度为原来二分之一的向量b,为何会出现Subscript indices must either be real positive integers or logicals.的错误?

a=[1,2,3,4,5,6,7,8,9,10];
for i=1:length(a)/2
b(i)=a(2*i);
end
改成上面的,b(i)=a(2*i);这句中乘法要加运算符的