- you are not capturing/saving every value of G. You probably want to use loop counter j. G(j) = 2.9+n;
- You are saving x using loop counter i. I think you want to use loop counter j.
- When plotting, MATLAB treats columns as series, not rows. If you want to plot G vs x, you need your series data to be in columns (assign x to a column in xnew, not a row). Same goes for G - series value goes in corresponding column. Also means swapping your preallocation dimensions - zeros(size-1,101).
- The output of the second for loop is a vector. You are getting an error on the assignment because of that. Your preallocation of xnew suggests you need to specify what rows and column to assign x to: xnew(:,j) = x;
- There is a mismatch between what the size of x is, and what the size of xnew is. You likely don't want to include the initial value for x, so when allocating to xnew, use xnew(:,j) = x(2:end)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/144763/image.png)