Scatter fails if all elements but one at index(1,1) are nan.

53 ビュー (過去 30 日間)
Joe Mueller
Joe Mueller 2024 年 11 月 4 日 5:31
コメント済み: Joe Mueller 2024 年 11 月 4 日 17:26
I am trying to use a scatter plot to visualize a 2-D histogram. I set all points with 0 hits to nan to improve the visualization of the scattering patterns. I get the following errors if there is just 1 non-NaN value in the data set:
"The logical indices contain a true value outside of the array bounds."
"Error in matlab.graphics.chart.primitive.internal.AbstractScatter/doUpdate"
In an attempt to debug the issue, I simplified the code to the following 5 test cases where the first generates the error and the others do not.
x0 = 1:14;
y0 = 1:19;
hits = nan( 19, 14 );
[x,y] = meshgrid( x0, y0 );
test_case = 1;
if test_case == 1 % fails (single non-NaN point at 1,2)
hits(1,2) = 1;
scatter( y(:), x(:), 20, hits(:), 'filled', 's' )
elseif test_case == 2 % passes (single non-NaN point at 1,1)
hits(1,1) = 1;
scatter( y(:), x(:), 20, hits(:), 'filled', 's' )
elseif test_case == 3 % passes (two non-NaN points)
hits(1,1) = 1;
hits(1,2) = 1;
scatter( y(:), x(:), 20, hits(:), 'filled', 's' )
elseif test_case == 4 % passes (all points are NaN)
scatter( y(:), x(:), 20, hits(:), 'filled', 's' )
elseif test_case == 5 % passes (random values; identify those > 0)
hits = randi( 4, size( hits ) ) - 1;
hits(hits<1) = nan();
scatter( y(:), x(:), 20, hits(:), 'filled', 's' )
end
Any help would be much appreciated!
  2 件のコメント
David Goodmanson
David Goodmanson 2024 年 11 月 4 日 5:50
編集済み: David Goodmanson 2024 年 11 月 4 日 5:59
Hi Joe, I tried this and all five cases worked including hits(1,1) = 1. I have Matlab 2023a Update 4
Joe Mueller
Joe Mueller 2024 年 11 月 4 日 16:23
Thanks! Walter Roberson indicated that this was a bug and fixed in 2023b.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2024 年 11 月 4 日 6:04
編集済み: Walter Roberson 2024 年 11 月 4 日 6:06
This is fixed in R2023b (maybe slightly earlier)
There does not appear to be any public bug report about this.
  1 件のコメント
Joe Mueller
Joe Mueller 2024 年 11 月 4 日 17:26
I downloaded R2023b and the issue is resolved! Thanks for the feedback.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by