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]

14 Comments

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.
Thanks - I have provided that now.
dpb
dpb on 21 Sep 2026 at 16:14
Edited: dpb on 21 Sep 2026 at 16:43
"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');
Yes I ran this code that you shared and I don't get the warning when running it?
With that approach, all the data are now single-precision.
Does that make a difference in the final result?
By code I was referring to:
M = 1713; N = 24001;
psd_dat = rand(M,N);
I can convert my data to single precision by:
single(psd_dat);
but I then get the warning:
Warning: An error occurred while drawing the scene: Error in web draw traversal: RangeError: Array buffer allocation failed
My solution works with MATLAB Online.
Is there a way to upload a large dataset for use in Matlab online though?
That likely depends on how large 'large' is.
Try it.
dpb
dpb on 28 Sep 2026 at 15:48
Edited: dpb on 28 Sep 2026 at 16:22
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?
Yes, so imagesc works but doesn't allow log axis?
And I don't believe I can upload a ~ 20 GB (sorry, I realised it was a thread below I mentioned this already) dataset online?
So, it seems that to I have to stick with imagesc and a linear axis.
Do you know a reasoning for the drive towards online? Wouldn't this impact a lot of researchers who use Matlab in remote locations?
You might be able to.
I still recommend that surf is a reasonable option, since you can define a log axis with it. You can do that either on MATLAB Drive or your own computer, depending on your available memory. You might be able to increase the memory that MATLAB can acess. (I have 64GB on both my laptop and desktop.)
dpb
dpb on 29 Sep 2026 at 12:33
Edited: dpb about 1 hour ago
"imagesc works but doesn't allow log axis?"
Yes, but as I noted before, take the log of the axes coordinates first, then write the axes ticklabels to match.
f_log = log10(f);
imagesc(t,f_log,psd_dat); % equivalent display to 'YScale'='log'
hAx=gca; % get the axes handle
hAx.YDir='normal'; % Ensure low frequencies are at the bottom
hAx.TickDir='out';
xtickformat(hAx,'dd-MM HH:mm');
xticks(hAx,t(1):0.5:t(end))
include_minor_ticks=true; % True to show minor divisions
[major_pos,major_lbls,minor_pos]=get_log_ticks(f,include_minor_ticks);
%include_minor_ticks=false; % Don't show minor divisions
%[major_pos, major_lbls,minor_pos]=get_log_ticks(f); % show major ticks only
hAx.YTick=major_pos;
hAx.YTickLabel=major_lbls;
if include_minor_ticks && ~isempty(minor_pos)
hAx.YAxis.MinorTick = 'on';
hAx.YAxis.MinorTickValues = minor_pos;
end
% HELPER FUNCTION (Place at bottom of script or save as get_log_ticks.m)
function [positions, labels, minor_positions] = get_log_ticks(y_vector, include_minor)
if nargin < 2, include_minor = false; end
y_min = min(y_vector);
y_max = max(y_vector);
start_exp = floor(log10(y_min));
end_exp = ceil(log10(y_max));
% Compute Major Ticks (Decades)
raw_major_ticks = 10.^(start_exp:end_exp);
valid_major_mask = (raw_major_ticks >= y_min) & (raw_major_ticks <= y_max);
filtered_majors = raw_major_ticks(valid_major_mask);
if isempty(filtered_majors) % Fallback for ultra-narrow bands
filtered_majors = linspace(y_min, y_max, 4);
end
positions = log10(filtered_majors);
%labels = string(filtered_majors); % ugly formatting
labels=arrayfun(@(p) sprintf('10^{%d}',p),filtered_exponents,'UniformOutput',0);
% Compute Minor Ticks
minor_positions = [];
if include_minor
raw_minor_ticks = [];
for exp_val = (start_exp-1):end_exp
raw_minor_ticks = [raw_minor_ticks, (2:9) * (10^exp_val)]; %#ok<AGROW>
end
valid_minor_mask = (raw_minor_ticks >= y_min) & (raw_minor_ticks <= y_max);
minor_positions = log10(raw_minor_ticks(valid_minor_mask));
end
end
I asked AI to generate a helper axis labelling function; the above is its output cleaned up a little to use the saved axes handle; modify to suit but it should be at least workable starting point although I didn't really test it. Note one of the fixups is to write the major labels as 10^p so will have to be sure to use the default 'TeX' interpreter or make a fixup otherwise.
I don't have any inside information on the eventual path MathWorks has in mind, just observing their reecent directions.

Sign in to comment.

Answers (3)

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 Comments

Thanks! Unfortunately I also get this warning message with surf().
Star Strider
Star Strider on 21 Sep 2026 at 4:08
Edited: Star Strider on 21 Sep 2026 at 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)
In order to upload your data to use with MATLAB Online, you will need to use MATLAB Drive.
.
I don't think this is an option as the data is ~ 20 GB?
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.

Sign in to comment.

dpb
dpb on 21 Sep 2026 at 19:54
Edited: dpb on 21 Sep 2026 at 21:52
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.
Antonio
Antonio 42 minutes ago
como usar o meu projeto para plotar graficos no Matlab?

Products

Release

R2026a

Asked:

on 16 Sep 2026 at 22:01

Answered:

about 8 hours ago

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!