Index exceeds the number of array elements.
古いコメントを表示
Hello everyone. I have a problem with error "Index exceeds the number of array elements. Index must not exceed 10.". I understand why theres an error but dont know how to work around it. The error message shows up because Iam comparing a value to nothing, but I need to do something with the last of the duplicates, which in this case is the last value of the array. I tried to explain the program and what it needs to do in each row.
x = [25 10 10 12 10 25 13 25 25 11]'; %input
x = sort(x,'descend'); %sorting from largest to smallest
x_pocet=numel(x); %number of values
dupli = grouptransform(x,x,@numel); %finding duplicates
for i=1:x_pocet %for i from 1 to number of values
if dupli(i)<=1 %if the value isnt a duplicate calculate profit
trzba = i*(x(i));
fprintf('\n Pro cenu %d. je trzba %d. \n',x(i),trzba)
else if dupli(i)>=1 && x(i)==x(i+1) %if the value is a duplicate and the value is same as the next one do nothing
else %if the value is a duplicate but is the last of the duplicates calculate profit
trzba = i*(x(i));
fprintf('\n Pro cenu %d. je trzba %d. \n',x(i),trzba)
end
end
end
If anyone could help me with solving the problem, it would be much appriciated.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!