How can I flip a row vector without using flip(lr) function?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
denizakyol
el 4 de Nov. de 2018
Comentada: Stephen23
el 15 de Oct. de 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
0 comentarios
Respuesta aceptada
Star Strider
el 4 de Nov. de 2018
Reverse the indices:
A = [1 2 -3 4];
B = A(numel(A):-1:1)
B =
4 -3 2 1
5 comentarios
Star Strider
el 4 de Nov. de 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.
Más respuestas (3)
Saad
el 15 de Oct. de 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 comentarios
Star Strider
el 15 de Oct. de 2022
@Saad —
The same as I originally posted, with an additional row dimension —
a = [1:4; 5:8; 9:12; 13:16]
b = a(:,size(a,2):-1:1)
.
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!