Single value in colors vector causes error in scatter plot

2 次查看(过去 30 天)
Hi,
I have the following code that works perfectly, the NaN values in the colors vector are skipped as desired:
>> colors = [NaN, 121, NaN, 150]
colors =
NaN 121 NaN 150
>> scatter([1,2,3,4], [1,2,3,4], 50, colors, 'filled');
which produces the following graph:
However, when i replace a value in the colors array with NaN it all goes wrong:
>> colors = [NaN, 121, NaN, NaN]
colors =
NaN 121 NaN NaN
>> scatter([1,2,3,4], [1,2,3,4], 50, colors, 'filled');
Warning: Error updating Scatter.
The logical indices contain a true value outside of the
array bounds.
Which stops the scatter graph from being plotted, it seems to happen when the vector is all NaN but one value.
Why does simply changing one of the values to NaN cause this error?
It doesn't matter which value is changed, but as soon as there is a single value surrounded by NaN's it will break.
Thanks in advance for any suggestions

采纳的回答

DGM
DGM 2021-11-30
The code you give works fine in the newest version that I have (R2019b), but not in R2021b. I'm not exactly sure what changed, so I can't do much to troubleshoot that, but I don't know that there's a need.
If you want to mask off points, it's probably better to simply omit the X and Y data directly. The input for the color property is subject to a bunch of conditional operations and scaling, so it kind of makes sense that it might explode if it only has one valid numeric value in the vector.
x = 1:4;
y = 1:4;
colors = [NaN, 121, NaN, NaN];
mk = ~isnan(colors);
scatter(x(mk), y(mk), 50, colors(mk), 'filled');
colorbar
caxis([1 256])

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Orange 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by