repeated row within a matrix

17 vues (au cours des 30 derniers jours)
Natasha Kratowska
Natasha Kratowska le 31 Août 2012
Hello,
Please help me with the following:
Consider an unknown number of vectors x.
This number is generated randomly.
All the vectors are 1x10.
Also, we have a specific vector m that is also 1x10.
How the matrix A is formed, where the vector m is repeated every second row?
For example, the rows of A are:
1st row: 1st vector
2nd row: vector m
3rd row: 2nd vector
4th row: vector m .
.
.
(x-1)th row: xth vector
xth row: vector m
Thank you very much.
Best,
Natasha

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 31 Août 2012
Modifié(e) : Azzi Abdelmalek le 31 Août 2012
n=randi(100,1)
x=rand(n,10)' % your n vector;
m=ones(1,10) % your special vector
y=repmat(m,n,1)'
res=[x;y];
result=reshape(res(:),10,2*n)'

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by