Tuesday, June 24, 2025

ncorr_2D_matlab (Compatibility with newer versions)

     This post is about running ncorr with newer versions of MATLAB. With help from [1], I edited the ncorr.m. The following section of the ncorr.m should be edited if MATLAB version is newer than 2023a. The code to be replaced starts at line 176 in the ncorr.m and continues till line 185. ncorr can be downloaded from [2].

Replace

% Initialize opengl ------------------------------------------%

% In earlier versions of Matlab this will fix inverted plots

% Plotting tools are also run based on opengl

if (ispc)

data_opengl = opengl('data');

if (~data_opengl.Software)

% Set opengl to software

opengl('software'); 

end

end

Replacement Code

if ispc

if verLessThan('matlab', '9.14') % R2023a or earlier

data_opengl = opengl('data');

if ~data_opengl.Software

opengl('software');

end

else

% In newer versions, opengl('data') is deprecated

info = rendererinfo(gca);

% Only set to software if info contains field 'GraphicsRenderer'

if isfield(info, 'GraphicsRenderer')

renderer_type = lower(info.GraphicsRenderer);

if ~contains(renderer_type, 'software')

opengl('software');

end

else

% If field is missing, assume hardware and force software

opengl('software');

end

end

end

References

[1] OpenAI. (2025). ChatGPT (June 2025 version) [Large language model].  https://chat.openai.com/chat

[2] https://github.com/justinblaber/ncorr_2D_matlab

No comments:

Post a Comment

ncorr_2D_matlab (Compatibility with newer versions)

     This post is about running  ncorr  with newer versions of MATLAB. With help from [1], I edited the ncorr.m. The following section of th...