Effacer les filtres
Effacer les filtres

how to create matrix from a row vector of different elements?

3 vues (au cours des 30 derniers jours)
scobug411
scobug411 le 8 Sep 2020
Modifié(e) : Adam Danz le 8 Sep 2020
for example creating y=[1 3; 2 4; 3 5] using A=[1:5]
i cannot use reshape because its a different number of elements
  1 commentaire
Adam Danz
Adam Danz le 8 Sep 2020
Modifié(e) : Adam Danz le 8 Sep 2020
What rule are you using for that transformation? For example, what would be the output for A=1:6?
Also, relace() is used with strings so why would you use that in the first place? Or are you using a different funcition with the same name?
For the example in your question,
y = reshape(A([1:3,3:5]),[],2);
but that won't work if A has a different length.

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 8 Sep 2020
The first and second columns are consecutive elements of ‘A’ although with an offset for the second column.
This is likely the easiest way:
Y = [A(1:end-2); A(3:end)].';
.

Plus de réponses (0)

Catégories

En savoir plus sur Operating on Diagonal Matrices 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