How can I flip a row vector without using flip(lr) function?

7 vues (au cours des 30 derniers jours)
denizakyol
denizakyol le 4 Nov 2018
Commenté : Stephen23 le 15 Oct 2022
I want to write a function that it can flip a row vector without flip(lr) function.
if true
% A=[1 2 -3 4]
And output must be:
B=[4 -3 2 1]
end

Réponse acceptée

Star Strider
Star Strider le 4 Nov 2018
Reverse the indices:
A = [1 2 -3 4];
B = A(numel(A):-1:1)
B =
4 -3 2 1
  5 commentaires
Star Strider
Star Strider le 4 Nov 2018
@Image Analyst — Good point. Thank you.
I wanted to make my code straightforward, the reason I wrote it as I did. I was not certain if using end would do that.
denizakyol
denizakyol le 4 Nov 2018
@Image Analyst Thank you so much. The end function is so helpful at all matrix operations. I would not forget anymore.

Connectez-vous pour commenter.

Plus de réponses (3)

Walter Roberson
Walter Roberson le 4 Nov 2018
B = flipud(A.').';

madhan ravi
madhan ravi le 4 Nov 2018
A=[1 2 -3 4]
B=wrev(A)
  1 commentaire
denizakyol
denizakyol le 4 Nov 2018
Thank you but I don't have Wavelet Toolbox. I want to write this function with matrix operations.

Connectez-vous pour commenter.


Saad
Saad le 15 Oct 2022
how to conver a matrix without using (flip function's)?for example
a= 1 2 3 4 b=4 3 2 1
5 6 7 8 8 7 6 5
9 10 11 12 12 11 10 9
13 14 15 16 16 15 14 13
  2 commentaires
Star Strider
Star Strider le 15 Oct 2022
@Saad
The same as I originally posted, with an additional row dimension —
a = [1:4; 5:8; 9:12; 13:16]
a = 4×4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
b = a(:,size(a,2):-1:1)
b = 4×4
4 3 2 1 8 7 6 5 12 11 10 9 16 15 14 13
.
Stephen23
Stephen23 le 15 Oct 2022
b = a(:,end:-1:1)

Connectez-vous pour commenter.

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