Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

repeat a matrix in defined manner

Asked by Rica on 12 Dec 2012

hi! How could i generate from this matrix:

 A=[1 2 3
    4 5 6  
    4 5 6]

this matrix:

 B= [1 1 1 1 2 2 2 2 3 3 3 3
     4 4 4 4 5 5 5 5  6 6 6 6 
     4 4 4 4 5 5 5 5  6 6 6 6]

thank you

0 Comments

Rica

Products

No products are associated with this question.

2 Answers

Answer by Azzi Abdelmalek on 12 Dec 2012
Edited by Azzi Abdelmalek on 12 Dec 2012
Accepted answer
A=[1 2 3;4 5 6;4 5 6];
m=4
B=cell2mat(arrayfun(@(x) x*ones(1,m),A,'un',0))

0 Comments

Azzi Abdelmalek
Answer by Walter Roberson on 12 Dec 2012
Edited by Walter Roberson on 12 Dec 2012
kron(A,[1 1 1 1])

or

A(:, repmat(1:end,4,1) )

0 Comments

Walter Roberson

Contact us