You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Matlab索引越界报错求助:id(90)访问超出numel(id)=89范围

排查MATLAB索引越界错误:Attempted to access id(90); index out of bounds

Hey there, let's work through this error you're hitting. First, let's break down what the error message is actually saying:

Attempted to access id(90); index out of bounds because numel(id)=89.Error in Untitled66 (line 26) person = find(id(fileNum)==ids);

This is telling you that you tried to access the 90th element of the id array, but id only has 89 elements total. The problem triggers at line 26 when you run id(fileNum)—that means the variable fileNum has a value of 90, which is larger than the maximum valid index of id (MATLAB uses 1-based indexing, so an array with 89 elements only goes up to index 89).

Let's go through the most likely causes and fixes:

  • fileNum is set to an invalid value
    Maybe you're incrementing fileNum in a loop, and it's going past the actual length of id. For example, if you hardcoded a loop to run from 1 to 90 but id only has 89 elements. To fix this, first check what fileNum is right before line 26—add disp(fileNum) above that line to see its value. Then adjust your loop to use the length of id as the upper bound:

    for fileNum = 1:length(id)
        % Your code here
    end
    
  • The id array is shorter than you expected
    Maybe you loaded or generated id incorrectly, and it only has 89 elements instead of the 90 you assumed. Verify its length by running numel(id) or length(id) in the command window. Double-check where id comes from—did you miss loading a data point, or is there a bug in the code that builds the id array?

  • You mixed up the indexing logic
    Looking at person = find(id(fileNum)==ids);—maybe you meant to compare the entire id array to a single element from ids, instead of grabbing one element from id to compare to ids? If ids is an array and you want to find positions in id that match ids(fileNum), the correct syntax would be:

    person = find(id == ids(fileNum));
    

    This way you're not indexing into id with fileNum, so you avoid the out-of-bounds error entirely (just make sure fileNum stays within the length of ids).

Try these steps one by one, and you should get this sorted out quickly!

内容的提问来源于stack exchange,提问作者popeye

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:26:03