How can I flip a row vector without using flip(lr) function?
조회 수: 6 (최근 30일)
이전 댓글 표시
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
채택된 답변
Star Strider
2018년 11월 4일
Reverse the indices:
A = [1 2 -3 4];
B = A(numel(A):-1:1)
B =
4 -3 2 1
댓글 수: 5
Star Strider
2018년 11월 4일
@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.
추가 답변 (3개)
Saad
2022년 10월 15일
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
Star Strider
2022년 10월 15일
@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)
.
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!