Effacer les filtres
Effacer les filtres

using Repmat function , obtain repeated specific values

2 vues (au cours des 30 derniers jours)
busra gogen
busra gogen le 12 Mai 2022
Commenté : busra gogen le 12 Mai 2022
z =[ 93 691 275 142 3 12]
n=6
for i=1:n
a=[1:n]'
b(i)=repmat(a(i),z(i),1)
end
I want to obtain repeated values of a in the matrix b but a(1) should be repeated in z(1) times, and a(2) should be repeated z(2) times. Above code just gived this:
b =
6
6
6
6
6
6
6
6
6
6
6
6
>>

Réponse acceptée

Steven Lord
Steven Lord le 12 Mai 2022
Use repelem.
a = [1 2 3 4]
a = 1×4
1 2 3 4
b = a.^2
b = 1×4
1 4 9 16
c = repelem(b, a)
c = 1×10
1 4 4 9 9 9 16 16 16 16
  1 commentaire
busra gogen
busra gogen le 12 Mai 2022
thank you, this is exactly what I want..

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by