Recursion revisited - can you help me?
5 次查看(过去 30 天)
显示 更早的评论
function v = reversal(v)
if length(v) > 1
v = [v(end) reversal(v(1:end-1))];
end
end
5 个评论
Walter Roberson
2021-6-28
Tests out okay
V = char(randi([33 126], 1, 31))
RV = reversal2(V)
isequal(RV, fliplr(V))
V = char(randi([33 126], 1, 32))
RV = reversal2(V)
isequal(RV, fliplr(V))
function v = reversal2(v)
if length(v) > 1
ii=round(length(v) /2 );
v = [reversal2(v(ii+1:end)) , reversal2(v(1:ii))];
end
end
回答(2 个)
ghazal
2022-7-2
I have problem and this is my code, anyone can help me?
function v=reversal(v)
if length(v)==1
ii=round(length(v)/2);
v=[reversal(v(ii+1:end)) , reversal(v(1:ii))];
end
end
3 个评论
ghazal
2022-7-3
Thanks friend for your explanation actually I don't get where the problem is, but I changed my code to this and I get this Error!
Error:
Undefined function 'reversal' for input arguments of type 'double'.
Code:
function v = reversal2(v)
if length(v) > 1
ii=round(length(v) /2 );
v = [reversal2(v(ii+1:end)) , reversal2(v(1:ii))];
end
end
Walter Roberson
2024-3-4
You would have a problem running function reversal when the function is named reversal2
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Visualize and Interpret Parallel Link Project Analysis Results 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!