MATLAB Answers

plz help how can repetition rows matrix

1 view (last 30 days)
eman baky
eman baky on 24 Jul 2021
Edited: eman baky on 24 Jul 2021
how can repetition rows matrix deponds number if i have a=[ 1 0 0 ;0 0 1; 0 1 0] and n=4
i wanna have rep_a=[ 1 0 0; 0 0 1; 0 1 0 ;1 0 0]
if n=5 rep_a=[ 1 0 0; 0 0 1; 0 1 0 ;1 0 0;0 0 1]

Accepted Answer

Jan
Jan on 24 Jul 2021
a = [1 0 0; 0 0 1; 0 1 0];
rows = size(a, 1);
n = 5;
index = rem(0:n-1, rows) + 1
index = 1×5
1 2 3 1 2
b = a(index, :)
b = 5×3
1 0 0 0 0 1 0 1 0 1 0 0 0 0 1

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!