How to decompose and expand a vector into ones

2 vues (au cours des 30 derniers jours)
Blue
Blue le 8 Août 2019
Commenté : Adam Danz le 9 Août 2019
Hi,
How would you decompose and expand a vector in Matlab ?
I might not be using the right terminology but let's I = [2, 2]'
How can I multiply that by 12 and get a 1x48 vector filled by ones ?

Réponse acceptée

Adam Danz
Adam Danz le 8 Août 2019
Modifié(e) : Adam Danz le 8 Août 2019
" I = [2, 2]' How can I multiply that by 12 and get a 1x48 vector filled by ones ?"
My interpretation: you want to multiply (or add?) the elements in I and then you want to multiply that result by 12 to get 48. Then create a row vector of 1s with length 48. Is that right?
I = [2, 2]';
x = ones(1,prod(I)*12); % prod() or sum() as in madhan's ans
the key is to use ones().
  2 commentaires
Blue
Blue le 9 Août 2019
You know you are indispensable, right ? Thanks.
Adam Danz
Adam Danz le 9 Août 2019
Ha! Glad I could help.

Connectez-vous pour commenter.

Plus de réponses (1)

madhan ravi
madhan ravi le 8 Août 2019
ones(sum(I)*12,1)
  2 commentaires
Adam Danz
Adam Danz le 8 Août 2019
"and get a 1x48 vector filled by ones"
You'd need to switch around those terms.
madhan ravi
madhan ravi le 8 Août 2019
Yup it was intentional.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by