MATLAB Answers

0

strcmpi not returning 1

Asked by Asahel Aguilar-Ortiz on 5 Dec 2019 at 1:08
Latest activity Commented on by Asahel Aguilar-Ortiz on 5 Dec 2019 at 1:28
% So I'm trying to find overlap between two strings. I am trying to use a logical index but compare never returns 1, any suggestions?
function [ combined, overlap ] = AssembleSeqs(left, right)
combined=[];
overlap=[];
shorter= min(length(left), length(right))
tester=[1:shorter];
for i=1:1:shorter
tester(i)=0;
leftend=left(end-i+1)
rightend=right(i)
compare=strcmpi('leftend','rightend')
if (compare==1)
tester(i)=1;
end

  0 Comments

Sign in to comment.

Products

1 Answer

galaxy
Answer by galaxy
on 5 Dec 2019 at 1:16
 Accepted Answer

You need compare string from 2 variables leftend and rightend, but you are comparing 2 string 'leftend' , 'rightend'.
Let remove apostrophe and sure about 2 variables leftend and rightend are string

  1 Comment

This did fix the problem. Such a simple error, thank you!

Sign in to comment.