Hey everyone, I need your help for a short moment. I used "scatter" to plot the following image.
I am quite happy with the image, but there is one problem. The data that I circled are NaN, but they simply get displayed as the lowest value by the scatter function. I tried to change the colorbar into ignoring NaN or making them invisible, but this did not work. Do you know a way to make the NaN values invisible (or simply remove them ?). The matrices I used to create this image are 11x11.

댓글 수: 3

It would be useful to know which of the inputs of scatter are NaN (The 4th input?) and exactly how you are invoking scatter.
The following works fine for me:
[x, y] = meshgrid(1:10);
c = 1:100;
c([10:10:40, 19, 29]) = nan;
scatter(x(:), y(:), [], c(:), 'filled');
The NaNs are not plotted (R2017a)
Hey, thank you for trying to help me. So I wrote some wrong stuff in the question (super tired). So my "code" is
scatter(alpha,beta,500,distance,'filled')
alpha and beta are both vectors with 121 entries (is this the right word ?). distance is also a vector with 121 entries and contains the NaNs. I used 500 for the size. I am currently working with matlab 2015b.
H ZETT M
H ZETT M 2017년 8월 1일
Oh well, I just figured out, that simply removing the NaNs while removing the entries from alpha and beta works fine. Thank you for your help anyway.

댓글을 달려면 로그인하십시오.

 채택된 답변

Guillaume
Guillaume 2017년 8월 1일

2 개 추천

As mentioned, the NaNs are correctly ignored in R2017a. I don't have R2015b installed anymore to test. You can easily work around the issue by removing the NaNs yourself:
nonans = ~isnan(distance);
scatter(alpha(nonans), beta(nonans), 500, distance(nonans), 'filled')

추가 답변 (1개)

Muhammad RSMY
Muhammad RSMY 2017년 9월 23일

0 개 추천

Data(isnan(Data))= 0;
idx = find(Data);
[X, Y] = ind2sub(size(Data), idx);
pointsize = 40;
scatter(X(:), Y(:), , pointsize, Data(idx),'square','filled');
colormap jet
colorbar

댓글 수: 1

Not sure why you're answering this 2 months after the question has been asked, particularly without any explanation.
Data(isnan(Data))= 0;
idx = find(Data);
[X, Y] = ind2sub(size(Data), idx);
Well, that's a very convoluted way of simply doing
[row, col] = find(~isnan(Data));
Note that conventionally row = Y and col = X.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

제품

질문:

2017년 8월 1일

댓글:

2017년 9월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by