How to generate reverse function

7 ビュー (過去 30 日間)
Ahmed Malik
Ahmed Malik 2021 年 2 月 8 日
回答済み: Image Analyst 2021 年 2 月 8 日
Write a matlab function called myReverseFunction. This function should accept
one vector as input parameter and return one vector as output parameter. This function should reverse the
location of elements from left to right. You should define a vector and call myReverseFunction.
Example: Example:
My vector is 1,3,5,7,6,11,22
Function returns 22,11,6,7,5,3,1

採用された回答

Walter Roberson
Walter Roberson 2021 年 2 月 8 日
SomeData = randi(9, 1, 10)
SomeData = 1×10
8 5 6 5 4 1 4 2 4 1
myReversFunction(SomeData)
ans = 1×10
1 4 2 4 1 4 5 6 5 8
function OtherData = myReversFunction(OtherData)
Flurp = (1:length(OtherData)).' == (length(OtherData):-1:1);
[~, Gurp] = max(Flurp,[],1);
OtherData = OtherData(Gurp);
end

その他の回答 (1 件)

Image Analyst
Image Analyst 2021 年 2 月 8 日
Hint: use the fliplr() function.

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by