how to reverse a string using a FOR loop

How to reverse a string without using functions like fliplr,flip etc.

 採用された回答

Ridwan Alam
Ridwan Alam 2019 年 12 月 14 日
編集済み: Ridwan Alam 2019 年 12 月 14 日

0 投票

Update:
myString = "abcdefg";
myChar = char(myString);
% using array indexing
myNewStr = string(myChar(end:-1:1));
% using FOR loop:
myNewChar = [];
for i = 1:length(myChar)
myNewChar = [myNewChar,myChar(end-i+1)];
end
myNewStr = string(myNewChar);
% myNewStr =
% "gfedcba"

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2019 年 12 月 14 日

編集済み:

2019 年 12 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by