Help with indexing error
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
William_M
am 2 Jun. 2018
Beantwortet: Walter Roberson
am 2 Jun. 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 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Denoising and Compression finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!