Create a matrix where the same row has been duplicated vertically up to a certain number

I'm trying to duplicate a row Xavg that is collected from another function called avg. When I use
disp (Xavg); % I can see that the system fetches the correct row.
Now I want to make a new matrix where I have duplicated this row a certain number of times vertically, which in my code I refer to as mX.
Also size from the matrix X is fetched correctly, where mX equals 10 rows.
Here is my code:
[mX nX] = size(X);
XXI = [];
XXII = [];
Xavg = avg(X);
for i = 1:mX
XXII = [XXI;Xavg];
end
disp (XXII );
Now the end result shows the row from Xavg, but only once, in other words it just shows the same rowvector unmodified and not the matrix I wished to get with the same rows duplicated vertically. Can anyone spot the error in my code?

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!