Plot not showing anything with too many NaNs
Show older comments
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")
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")
x3 = paddata(x2, 17, Dimension = 2, FillValue = 42, Side = "trailing")
Michal Dudek
on 23 Apr 2026
Edited: Michal Dudek
on 23 Apr 2026
Michal Dudek
on 23 Apr 2026
Michal Dudek
on 27 Apr 2026
Accepted Answer
More Answers (0)
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!