"anil chandy" <anilvchandy@gmail.com> wrote in message <gmtqu1$1os$1@fred.mathworks.com>...
> is there any method to make a the columns repeat in matrix.. ie i ve a matrix wit values
> 0.012727 0.0095914 0.014579
> 0.019345 0.025261 0.0071265
> 0.058444 0.058444 0.045653
> 0.91262 0.91262 0.93264 etc.......and another matrix wit values
>
>
> 43
> 23
> 45
> etc
> i weanna make the first column repeat 43 times ,2nd column 23 times 3rd one 45 times.. can anyone pls help me out....
An example:
DATA = [10 20 30 ; 11 21 31 ; 12 22 32 ; 13 23 33 ; 14 24 34]
We want to have column 1 to be present 3 times, column 2 once, and column 3 twice:
R = [3 1 2] ;
We might do this by hand:
idx = [1 1 1 2 3 3] ;
newdata = DATA(:,idx)
The problem has become: how to derive idx from R. One approach, separated in multiple commands for clarity:
R = [3 1 2] ;
p = cumsum(R)+1 % where does the next column start
idx = zeros(1,p(end)) % initialize
idx(p) = 1 % set the positions to 1
idx = idx(1:end1) ; % ignore the last one
idx = cumsum(idx)
idx = idx+1
newdata2 = DATA(:,idx)
This code can be condensed.
hth
Jos
