Plotting images in Matlab 2026a
显示 更早的评论
I frequently work with large matrices and usually I can use pcolor to plot these - but since I updated Matlab to 2026a I get an error everytime I use the same code to do something which worked in Matlab 2024a.
I can't share my data, but my code is as follows - where t is a 1713x1 datetime array; f is a 1x24001 double array and psd_dat is 1713*24001 double matrix.
I tried to use imagesc instead, and this works, but doesn't allow me to shift the y axis to a log scale, which I need to do. In the past, pcolor allowed me to do this easily.
Thanks for your help and please let me know if I can provide any further detail!
The Warning message (whether using pcolor or surf) is:
Warning: An error occurred while drawing the scene: Error in web draw traversal: RangeError: Array buffer allocation failed
pcolor(t,f,psd_dat,'edgecolor','none');
%imagesc(t,f,psd_dat);
%axis xy;
set(gca,'tickdir','out') %set tick marks to point outwards
xtickformat('dd-MM HH:mm');
xticks(t(1):0.5:t(end))
set(gca,'YScale','log');
[Removed extra quote on psd_dat variable in two places--dpb]
10 个评论
Steven Lord
2026-9-17,5:49
but since I updated Matlab to 2026a I get an error everytime I use the same code to do something which worked in Matlab 2024a.
Please show us the full and exact text of the error message, all the text displayed in red in the Command Window (and if there are any warning messages displayed in orange, please show us those too.) The exact text may be useful and/or necessary to determine what's going on and how to avoid the warning and/or error.
Louise Wilson
2026-9-21,2:40
"I can't share my data, ..."
"The Warning message (whether using pcolor or surf) is:"
Warning: An error occurred while drawing the scene: Error in web draw traversal: RangeError: Array buffer allocation failed
Just to prove it's a memory-related issue, try
M = 1713; N = 24001;
psd_dat = rand(M,N);
and see if the same error doesn't occur.
One could do some binary searching and see at what point/size the error begins to occur...alternatively, one could check that it is an indexing issue or an actual allocation issue by
pcolor(single(t),single(f),single(psd_dat),'edgecolor','none');
Louise Wilson
about 10 hours 前
Star Strider
about 10 hours 前
With that approach, all the data are now single-precision.
Does that make a difference in the final result?
Louise Wilson
about 8 hours 前
Star Strider
about 6 hours 前
Louise Wilson
about 4 hours 前
Star Strider
about 3 hours 前
That likely depends on how large 'large' is.
Try it.
The test and subsequent (expected) failure with single precision data confirms it is still memory limited as internally everything is still rendered using doubles.
The issue is that PCOLOR() memory use explodes from the physical array size by a multitude of internal pieces generated -- it isn't just the 2D array x 3 byte RGB color but it generates a complex Surface graphics object. Behind the scenes, every quad polygon cell expands into arrays containing:
- X, Y, Z Spatial Coordinates (3 coordinates × 8-byte double per vertex)
- Color Mapping Indices (8-byte double per vertex)
- Vertex Normals for shading/lighting (3 vectors × 8-byte double per vertex)
Consequently, your matrix of ~800MB in the MATLAB workspace requires over 4GB in the graphics system. Begining in R2025a, desktop graphics are rendered using an embedded Chromium/WebGL 2.0 engine which is constrained by a 2GB limit on any single, contiguous array allocation (ArrayBuffer). As we just proved, converting the input to single precision doesn't matter because internally everything is turned back into doubles, anyway. (I was virtually positive that would be the case, just wanted to test to be sure.)
OTOH, MATLAB Online uses multiple cloud worker nodes that handle the heavy data serialization on the server-side providing prepared graphics to your browser instead of using a single local WebGL memory buffer.
As noted before, the local alternative would still be to switch to IMAGESC() or, as @Star Strider suggests, if you can, use the Online version where MathWorks is trying to push users, anyway; may eventually be the only option, who knows?
回答(2 个)
Star Strider
2026-9-17,1:39
I am not certain what you want, however one option is to use surf and then rotate it with the view function. Also, 'interp' might be a better choice for EdgeColor.
I can't get this to run here, however MATLAB Online produces this result using a calculated Gaussian as the 'image' --
clear all
close all
tic
t = datetime('now') + hours(0:1712).';
f = linspace(0, 100, 24001);
psd_dat = exp(-((0:numel(t)-1).'-800).^2/2E+5) * exp(-(f - 50).^2/1000) * 1000;
[mindat,maxdat] = bounds(psd_dat(:))
% figure
% contour(psd_dat')
%
% toc
%
% return
% figure
% surf(psd_dat.', EdgeColor='interp')
% colormap(turbo)
% title('Surface Plot')
figure
% surf(t,f,psd_dat','edgecolor','none');
surf(t,f,psd_dat','edgecolor','interp') % <-- ChANGED
%imagesc(t,f,psd_dat');
%axis xy;
set(gca,'tickdir','out') %set tick marks to point outwards
xtickformat('dd-MM HH:mm');
xticks(t(1):0.5:t(end))
set(gca,'YScale','log');
view(0,90) % <-- ADDED
toc

The image was copied and pasted.
.
4 个评论
Louise Wilson
2026-9-21,2:41
Star Strider
2026-9-21,4:08
编辑:Star Strider
2026-9-21,20:42
My pleasure!
The error indicates to me that you may be having memory problems. You should have access to MATLAB Online, so try it there as well.
It worked for me without any warning messages or errors, however I don't have your data.
EDIT -- (21 Sep 2026 at 20:42)
.
Louise Wilson
about 11 hours 前
Star Strider
about 10 hours 前
I created my vectors and matrix to match 't is a 1713x1 datetime array; f is a 1x24001 double array and psd_dat is 1713*24001 double matrix'. If that information still holds, my version of your code should work. (I had to create the figure in MATLAB Online since it is too large to work here. I suggested the same approach to you as well., I added a link to the MATLAB Drive documentation so you could create it and upload your matrix to it to use with MATLAB Online.)
I used the same code that I posted for this. The commented-out code was to verify that I had created the matrix correctly, and that the plot worked. I commented it out because running it as well as the last image requires too much memory, so I suggest that you leave it commented out as well. Running it separately is an option, however.)
All you will need to do is to load 'psd_dat' instead of creating it, as I did.
R2025+ shifted away from OpenGL to the Chromium browser-based WebGL renderer which is limited to a 2GB memory footprint. pcolor will try to generate some 40+M polygons and exceeds that allowable memory. Probably the simplest workaround is to log transform the y axes values directly for imagesc and then write the ticklabels to match depending upon the actual frequency scaling/range. You'll want to set YDir to 'Normal' to keep the same orientation as pcolor
The alternative to still be able to use pcolor() would be to downscale sufficiently to not exceed the 2GB memory limit.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!