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

matrix operation make matrix

Asked by Internazionale on 23 Mar 2013

i want to make matrix. for manual way or the output

A=[1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 ... 8 8 8 8 8 8 8 8];

for A, each value until 8 times the value will be add by 1.

b=[1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 ... 1 2 3 4 5 6 7 8];

for b, value 1-8 will be looping until 8 times.

so the size A is 1x64 and B is 1x64

2 Comments

Andrei Bobrov on 23 Mar 2013
A = kron(1:8,ones(1,8));
B = kron(ones(1,8),1:8);
Azzi Abdelmalek on 23 Mar 2013

kron is less faster

Internazionale

Tags

Products

No products are associated with this question.

2 Answers

Answer by Azzi Abdelmalek on 23 Mar 2013
Accepted answer
a=repmat(1:8,8,[]);
b=a'
a=a(:)'
b=b(:)'

0 Comments

Azzi Abdelmalek
Answer by Matt Kindig on 23 Mar 2013
A = reshape(repmat((1:8), 8, 1), 1, [])
b = repmat(1:8, 1, 8)

0 Comments

Matt Kindig

Contact us