필터 지우기
필터 지우기

How to plot x,y, and intensity with NaN values present in the intensity data?

조회 수: 2 (최근 30일)
Here is my code for my attempt to plot x, y, and intensity (referred to as v) on a color plot. I keep running into an issue where I cannot find the maximum of intensity due to NaN's present. Any advice to mitigate this issue or help refining this code is welcome. Thanks!
%plotting script
% Make an image of the points, then apply a colormap
x = x(:); % Extract x value
y = y(:); % Extract y value
v = v(:); % Extract intensity value
%find max and min values
minX = min(x,[],1);
maxX = max(x,[],1);
minY = min(y,[],1);
maxY = max(y,[],1);
[minV,~] = nanmin(v);
[maxV,~] = nanmax(v);
% Make image be 500 by 700
rows = 500;
columns = 700;
grayImage = zeros(rows, columns, 'uint8');
for k = 1 : length(x)
row = ceil((y(k) - minY) * rows / (maxY - minY));
column = ceil((x(k) - minX) * columns / (maxX - minX));
if (row == 0)
row = 1;
end
if (column == 0)
column = 1;
end
grayImage(row, column) = uint8(255 * (v(k) - minV) / (maxV - minV));
end
imshow(grayImage);
colorbar;
% Colormap is not gray scale.
% Apply some other colormap if you want
colormap(jet(256));
  댓글 수: 1
Walter Roberson
Walter Roberson 2017년 9월 25일
You appear to me to be properly using nanmin() and nanmax().
The only thing I see is that you have been a little lax about handling v(k) being nan. Your calculation will result in uint8(nan) which turns out to be 0. If that is the result you want then I recommend adding a comment about that.
Also, the calculations (maxY - minY) and (maxV - minV) can be done ahead of time and stored in variables instead of being done every iteration. Also watch out for the possibility of constant input, in which case (maxV - minV) would be 0.

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

답변 (1개)

Image Analyst
Image Analyst 2017년 9월 25일
편집: Image Analyst 2017년 9월 25일
I don't see any plotting going on. Anyway, to extract only non-NaN values from an array, such as grayImage or v or whatever, do this:
goodValues = v(~isnan(v));
Then you can get the max, min, mean, etc. of those good values.
  댓글 수: 6
Image Analyst
Image Analyst 2017년 9월 25일
편집: Image Analyst 2017년 9월 25일
We don't have your v so can't even run your code. So I quit at that point. Can you attach v in a .mat file, so we can try to help you?
Walter Roberson
Walter Roberson 2017년 9월 26일
In my test, I do not get index out of range.
Note: to get your color right, you should do
cmap = jet(256);
imshow(grayImage, cmap);
colorbar();
without calling colormap() after that.

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

카테고리

Help CenterFile Exchange에서 Blue에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by