Plot not showing anything with too many NaNs

I am trying to plot a series of data in a wrapped plot using code as below.
mult = 100; % 1 or 1e4; 694 = max
am = 100*mult;
a = [NaN(1700*mult-1-am,1);rand(1728*mult,1)-0.5]; % add NaN to the left side
a = [a;NaN(48*2*36*mult-length(a),1)]; % add NaN to the right side whlie keeping constant size
a = reshape(a,36*mult,[]); % convert to wrapped data
a = a - repmat(0:47,1,2); % subract 1 from each consecutive line to be shown on the same plot
for jj = 0:1
figure(10+jj), clf
C = colororder;
colororder(C(1:2,:)) % keep only two colors
plot(1:36*mult,a(:,(1:48)+jj*48)')
xlim([1,36*mult])
ylim([-48,1])
end
When mult is set in the range from 1 up to 694, both of the plots show correct results with blank spaces for missing data (as intended), as shown in images below.
When mult is set to 695 and above (e.g. 1000), the plots are not produced at all, and I get warnings as shown below.
On the other hand, even when mult is set to high values (e.g. 1000), but am (which shifts the data) is set to 0, effectively resulting in only the last line in the plot having missing data, the second plot is shown correctly, as below, while the first one produces the same warnings again.
To summarize, for large sets of data, when trying to plot multiple datasets consisting only of NaNs, the plot does not work properly. Is there a way to fix this?

4 Comments

This is independent of the plot question, but as an FYI you could use the resize function to pad your data with NaN in one line if you want the data to be centered in the resulting array.
x = 1:5;
y = resize(x, 10, Dimension = 2, FillValue = NaN, Side = "both")
y = 1×10
NaN NaN 1 2 3 4 5 NaN NaN NaN
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
The resize call makes an array whose size in Dimension 2 is 10, filling in the necessary values on both Sides (leading and trailing edges), using a FillValue of NaN.
If you didn't want it centered, you could use paddata instead of having to build the arrays of NaN values yourself.
x2 = paddata(x, 10, Dimension = 2, FillValue = NaN, Side = "leading")
x2 = 1×10
NaN NaN NaN NaN NaN 1 2 3 4 5
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
x3 = paddata(x2, 17, Dimension = 2, FillValue = 42, Side = "trailing")
x3 = 1×17
NaN NaN NaN NaN NaN 1 2 3 4 5 42 42 42 42 42 42 42
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
@Steven Lord, thank you for your comment! It is realy helpful as I was not aware of this functionality.
After some tests I foud out that my method is faster than using paddata twice. Both paddata and resize do not allow to select how many additional fill values should be on each side of input data at the same time.
I can confirm that this is an issue with the 'WebGL' renderer, as suggested by @Star Strider. I tested the code on MATLAB 2022a with the 'OpenGL Hardware' renderer and it worked just fine.
Updating MATLAB to R2026a solved this issue.

Sign in to comment.

 Accepted Answer

You will most likely need to Contact Support for this problem.
Include the URL of this thread in your note to MathWorks so you don't have to repeat everything you wrote here.
This seems to be inherent to the code for plot. The renderer is WebGL, and that may be the problem.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products

Release

R2025b

Community Treasure Hunt

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

Start Hunting!