symmetrical character array with only letters
3 次查看(过去 30 天)
显示 更早的评论
Im trying to make a function that gives a logical true if the character array is symmetrical and logical false if not.
So far I have:
a = 'abba'
isItSym = isequal(a(:),flip(a(:)))
res = isItSym
But for anything that is not A-Z or a-z it needs to come back as logical false and it does not (ex: 'p##p').
Im thinking some sort of if function with an sprintf to split the array up and then find any false values with char(0:64) and so on. Im a little new with matlab tho so im having trouble goin about this. Thanks!
0 个评论
采纳的回答
Voss
2022-2-20
编辑:Voss
2022-2-20
Use isstrprop():
a = 'abba';
isItSym = isequal(a(:),flip(a(:))) && all(isstrprop(a(:),'alpha'))
a = 'p##p';
isItSym = isequal(a(:),flip(a(:))) && all(isstrprop(a(:),'alpha'))
5 个评论
DGM
2022-2-22
编辑:DGM
2022-2-22
a = 'abba';
isItSym = ~isempty(a) && isequal(a(:),flip(a(:))) && all(isstrprop(a(:),'alpha'))
a = 'abbc';
isItSym = ~isempty(a) && isequal(a(:),flip(a(:))) && all(isstrprop(a(:),'alpha'))
a = 'a##a';
isItSym = ~isempty(a) && isequal(a(:),flip(a(:))) && all(isstrprop(a(:),'alpha'))
a = '';
isItSym = ~isempty(a) && isequal(a(:),flip(a(:))) && all(isstrprop(a(:),'alpha'))
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!