フィルターのクリア

how to reverse a string using a FOR loop

5 ビュー (過去 30 日間)
Kathrin Chari
Kathrin Chari 2019 年 12 月 14 日
編集済み: Ridwan Alam 2019 年 12 月 14 日
How to reverse a string without using functions like fliplr,flip etc.

採用された回答

Ridwan Alam
Ridwan Alam 2019 年 12 月 14 日
編集済み: Ridwan Alam 2019 年 12 月 14 日
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 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by