turn function to recursive
조회 수: 1 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Debugging and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!