how to stop while statement
Afficher commentaires plus anciens
function isitalike=comparestrings(a,b)
n=length(a);
m=length(b);
c=logical(0);
y=m;
z=n;
f=0;
if m>n
temp=a;
a=b;
b=temp;
end
for i=1:n
c=strcmp(a(i),b(1))
if c
j=1;
if a(i:n)>=length(b)
for k=1:length(b)
while a(i)==b(j)
if j==length(b)
if z>y
disp('b is in a')
f=1;
else
disp('a is in b')
f=1;
end
end
j=j+1;
i=i+1;
end
end
end
end
end
if f==0
if z>y
disp('b is not in a')
else
disp('a is not in b')
end
end
The function above does not work properly I can't stop the while statement after i have found that a is in b or b is in a. This is what happens:
>> a
a =
agg
>> b
b =
sagggsa
>> comparestrings(a,b)
c =
0
c =
1
a is in b
??? Attempted to access b(4); index out of bounds because
numel(b)=3.
Error in ==> comparestrings at 39
while a(i)==b(j)
>>
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!