MATLAB: How to compare columns in a string matrix

column vectorcolumnscompareendforloopMATLABmatrixstringvector

I have a given string matrix and I need to check if the word can be read the same from the opposite direction (that it is to say if it is a Palindromes like -live not on evil)
%

wordList = ['civic';'dream';'kayak';'level';...
'lower';'peace';'radar';'refer';'table';'stats']
if the word is read the same from both direction I have to put 1 in the vector palRes(10,1) if not – I have to put 0 in it…
what I have done:
%
wordList = ['civic';'dream';'kayak';'level';...
'lower';'peace';'radar';'refer';'table';'stats']
wordList1 = fliplr(wordList)
palRes=zeros(10,1)
for ii= 1:size(wordList,1)
for jj = 1:size(wordList,2)
if wordList(ii)== wordList1(ii)
palRes(ii,jj) = 1
end
end
end
but the problem is that the final palRes that I get is a(10,5)matrix instead of (10,1) vec I want to fix this problem inside the loop and not after it! any ideas? thanks!

Best Answer

Instead of that inner for-loop with the index jj, use the 'all' function:
palRes(ii) = all(wordList(ii)==fliplr(wordList(ii));