Help with indexing error
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
William_M
le 2 Juin 2018
Réponse apportée : Walter Roberson
le 2 Juin 2018
function B = Ecomp(e,f)
%Compares 2 elements of equal length (unfactored) in
%Sn and sees if theyre the same, i.e cyclic permutations of each other.
B='TRUE';
k=0;
n=length(e);
for i = 1:n
if f(i) == e(1)
k=i;
end
end
for j = 1:n-1
if f(mod(k+j,n)) ~= e(j+1)
B='FALSE';
return
end
end
end
This function is supposed to compare two vectors and see if they are cyclic permutations of each other. For example, Ecomp([1,2,3,4],[4,1,2,3]), should return 'TRUE', however when I input this the error that I get is:
>> Ecomp([1,2,3,4],[4,1,2,3])
Subscript indices must either be real positive integers or logicals.
Error in Ecomp (line 13)
if f(mod(k+j,n)) ~= e(j+1)
I can't see why as my indexing starts from 1, any help much appreciated.
0 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Denoising and Compression dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!