string as input for function

조회 수: 6 (최근 30일)
Espen
Espen 2011년 11월 7일
this function handles a string as input:
function rev=stringrev(a)
n=length(a);
for i=1:n
b(i)=a(n-i+1);
end
rev=b;
but this does not:
function palindrom=checkpalin(a)
rev=stringrev(a);
if strcmp(rev,a)
palindrom=sprintf('%s is a palindrom', rev)
else
palindrom=sprintf('%s is not a palindrom', rev)
end
what is the difference?
This is what happens when I run them in matlab:
>> b='astsa'
b =
astsa
>> checkpalin(b)
??? Undefined function or method 'checkpalin' for input arguments of type 'char'.
>> a='iceice'
a =
iceice
>> stringrev(a)
ans =
ecieci
>>

채택된 답변

Grzegorz Knor
Grzegorz Knor 2011년 11월 7일
Are you sure that you have not done a typo in the filename? I've tested your functions, and they work.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by