フィルターのクリア

turn function to recursive

1 回表示 (過去 30 日間)
amateurintraining
amateurintraining 2017 年 10 月 20 日
回答済み: Walter Roberson 2017 年 10 月 20 日
I have a function:
function [ array2 ] = charReversal( array1 )
%CHARREVERSAL reverses a character array using recursion
n=length(array1);
if n>1
array2=[array1(end) array1(2:end-1) array1(1)];
array2=[array2(1) array2(end-1) array2(3:end-1-1) array2(1+1) array2(end)];
array2=[array2(1:2) array2(end-2) array2(4:end-1-1-1) array2(1+1+1) array2(end-1:end)];
else
array2=array1;
end
But I don't know how to turn it into a recursive function. I have tried:
function [ array2 ] = charReversal( array1 )
%CHARREVERSAL reverses a character array using recursion
n=length(array1);
if n>1
array2=charReversal([array1(end) array1(2:end-1) array1(1)]);
else
array2=array1;
end
I am having a little trouble with the idea of recursive functions.

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 10 月 20 日

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by