matlab expand matrix
I am looking for a code that will repeat each column of a vector to produce a new vector...
-------------------------
So if I understand you correctly, you want a vector
a = [1 2; 3 4];
and you pass expand (a, 3) you get
1 1 1 2 2 2
3 3 3 4 4 4
if this is correct, the proper way of implementing it it is like this:
function y = expandB(b, m)
y=reshape(repmat(b',1,m)', length(b
,1)), m*length(b(1,: )));
That's it. As a test, I passed
b = ones(100, 1000)
m = 500
my version took 1.318641 seconds. Thats tiling out a 100x1000 matrix 500 times!
Communications_Engineer said "For a matrix size of 4x2000, it will always take a lot of time"
This is wrong, wrong, wrong. Matlab LOVES to process matrices, you got gotta understand how it does it so you don't artificially slow it down.
The general rule for Matlab is "If you are using a for loop, you are probably doing it wrong."
Seriously, Matlab is NOT optimized for looping. The more you learn to vectorize everything, the better your programs will work