cellfun 반복문 사용 시, matlab 강제 종료 현상
Mostrar comentarios más antiguos
point_LumY_num(1, :) = [19 19 19 19 19 19 2 2 2 2 2 2 2 2 36 36 36 4 4 4 4 4 4 4 4 53 53 53 53 53 53 68 68 68 68 68 68 68 68 6 6 6 6 6 6 6 6 70 70 70 70 70 70 70 70 72 72 72 72 72 72 72 72]
point_LumY_num(2, :) = [153 155 157 2 4 6 105 122 139 20 37 54 71 88 2 4 6 105 122 139 20 37 54 71 88 153 155 157 2 4 6 105 122 139 20 37 54 71 88 105 122 139 20 37 54 71 88 105 122 139 20 37 54 71 88 105 122 139 20 37 54 71 88]
Base_HIAA_Top = ...
{[00, 000], [00, 000], [00, 000], [19, 157], [00, 000], [53, 157], [00, 000], [00, 000], [00, 000];...
[00, 000], [00, 000], [00, 000], [19, 155], [00, 000], [53, 155], [00, 000], [00, 000], [00, 000];...
[00, 000], [00, 000], [00, 000], [19, 153], [00, 000], [53, 153], [00, 000], [00, 000], [00, 000];...
[02, 139], [04, 139], [06, 139], [00, 000], [00, 000], [00, 000], [68, 139], [70, 139], [72, 139];...
[02, 122], [04, 122], [06, 122], [00, 000], [00, 000], [00, 000], [68, 122], [70, 122], [72, 122];...
[02, 105], [04, 105], [06, 105], [00, 000], [00, 000], [00, 000], [68, 105], [70, 105], [72, 105];...
[02, 088], [04, 088], [06, 088], [00, 000], [00, 000], [00, 000], [68, 088], [70, 088], [72, 088];...
[02, 071], [04, 071], [06, 071], [00, 000], [00, 000], [00, 000], [68, 071], [70, 071], [72, 071];...
[02, 054], [04, 054], [06, 054], [00, 000], [00, 000], [00, 000], [68, 054], [70, 054], [72, 054];...
[02, 037], [04, 037], [06, 037], [00, 000], [00, 000], [00, 000], [68, 037], [70, 037], [72, 037];...
[02, 020], [04, 020], [06, 020], [00, 000], [00, 000], [00, 000], [68, 020], [70, 020], [72, 020];...
[00, 000], [00, 000], [00, 000], [19, 006], [36, 006], [53, 006], [00, 000], [00, 000], [00, 000];...
[00, 000], [00, 000], [00, 000], [19, 004], [36, 004], [53, 004], [00, 000], [00, 000], [00, 000];...
[00, 000], [00, 000], [00, 000], [19, 002], [36, 002], [53, 002], [00, 000], [00, 000], [00, 000];...
};
for i = 1:63
cellSearch1 = cellfun(@(x1) isequal(x1, [point_LumY_num(1, i),point_LumY_num(2, i)]), Base_HIAA_Top, 'UniformOutput', false); cellSearch1 = cell2mat(cellSearch1);
[nR, nC] = find(cellSearch1 == 1);
map_LumY_ori(nR(1), nC(1)) = point_LumY_scr(i);
pause(0.001); %to prevent force exit
end
상기 코드처럼 진행을 했을 때, pause를 사용하지 않고 코드를 진행하면 matlab 2022b 기준으로 매트랩이 갑자기 종료되는 현상이 반복 됩니다
전체 코드 기준으로 200번 정도 위 코드가 반복되는데 log를 남겨 살펴보아도 특정 지점이 아닌 random하게 지속 강제 종료 됩니다
Respuestas (1)
Rajasekhar
el 29 de Abr. de 2026 a las 9:35
Based on the above code, the crash could be due to one of the following reasons:
- No preallocation: If map_LumY_ori is not initialised before the loop, repeated dynamic resizing can cause memory issues.
- Invalid indexing: If find returns empty results, accessing nR(1) or nC(1) leads to invalid indexing and may destabilise MATLAB.
Suggested fixes:
- Preallocate map_LumY_ori before entering the loop.
- Validate indices before assignment, for example:
if ~isempty(nR) && ~isempty(nC)
map_LumY_ori(nR(1), nC(1)) = point_LumY_scr(i);
end
- Additionally, the code can be further optimised by improving the search logic. For guidance, refer to the following documentation: Techniques to Improve Performance - MATLAB & Simulink
Categorías
Más información sobre Whos en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!