Help with indexing error

1 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2018-6-2
mod() can return 0.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Denoising and Compression 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by