MATLAB: How to fix the error “Index exceeds matrix dimension”

index exceeds matrix dimensions

In my FEM program, I want to build a matrix bcdof[1;2;7;8;67;68;69;70;71;72] from matrix bcdof1=[1;4;34;35;36] but the program say that "Index exceeds matrix dimension". Can anyone help me, here is my code:
bcdof1=[1;4;34;35;36];
bcdof=zeros(1,2*length(bcdof1));
for i=1:length(bcdof1)
bcdof(1,(2*i-1))=2*bcdof1(1,i)-1;
bcdof(1,(2*i))=2*bcdof1(1,i);
end

Best Answer

bcdof1 is a column vector you need to index bcdof1(i,1) instead of bcdof(1,i)
bcdof1=[1;4;34;35;36];
bcdof=zeros(1,2*length(bcdof1));
for i=1:length(bcdof1)
bcdof(1,(2*i-1))=2*bcdof1(i,1)-1;
bcdof(1,(2*i))=2*bcdof1(i,1);
end