MATLAB: ERROR USING VERTCAT HELP PLEASE

errorvertcat

I keep getting this error
"Error using vertcat Dimensions of matrices being concatenated are not consistent."
P=(100:100:1000);
for i=1:P
D = [1 0 0 -0.857 -0.832 -0.812;
0 1 0 0.286 0.555 0.542;
0 0 1 0.429 0 -0.217;
0 0 0 0 0 0.0379;
0 0 0 -0.1286 0 0.1218;
0 0 0 0.0857 0.1664 0.1625;];
E= [0;
P;
0;
0.15.*P;
0;
0.3.*P;];
X=D\E;
end

Best Answer

It is unclear what you are trying to do with the loop. P is a vector [100 200 ... 1000], so the for loop indexing i=1:P doesn't seem to make sense. And then inside your matrix building you have scalars mixed in with this P vector for the concatenation, hence the error. Did you mean to do this instead?
P=(100:100:1000);
for k=P
D = [1 0 0 -0.857 -0.832 -0.812;
0 1 0 0.286 0.555 0.542;
0 0 1 0.429 0 -0.217;
0 0 0 0 0 0.0379;
0 0 0 -0.1286 0 0.1218;
0 0 0 0.0857 0.1664 0.1625;];
E= [0;
k;
0;
0.15.*k;
0;
0.3.*k;];
X=D\E;
end