MATLAB: How to creating matrix h 4×2 with some rules

matrix manipulationreshape matrix

I have some trouble when creating matrix 4×2 with rules like below. the first column are integer and the other column are random number. I already create the syntax below.
for ii = 1:8,
nilai = mod(ii,2);
if nilai == 0
x(ii) = 0.95 + (1.05-0.95)*x(ii);
elseif nilai ~= 0
x(ii) = round(3 + (30-3)*x(ii));
elseif nilai ~= 0
x(ii) = 0.01 + (0.055-0.01)*x(ii);
else
x(ii) = 1.0 + (1.15-1.0)*x(ii);
end
end
x = reshape(x,4,2)';
but the result are
??? Error using ==> reshape
To RESHAPE the number of elements must not change.
anyone can help me with this problem..? any solutions are very welcome..
thank you.

Best Answer

What is the shape of x before you start? It seems that it is probably not an 8-element array, so the reshape fails.