How do I plot one matrix as a function of another?

2 次查看(过去 30 天)
I am trying to create a plot of intensity versus distance. I have one matrix containing distance values from a few points, created by bwdist. I have another matrix simply full of intensity values. They are the same size.
I would like a 2D plot exhibiting how intensity changes with distance from the points. The trouble I'm having is the plot function only plots columns of matrices against each other. I need to be able to plot an absolute distance as provided by the matrix with distance values, uninhibited by the column/row distinction.
Thank you

回答(2 个)

dpb
dpb 2017-4-12
编辑:dpb 2017-4-12
[~,ix]=sort(distanceArray(:)); % get order vector of distances in the distance array
plot(distanceArray(ix),intensityArray(ix)) % plot in ascending order
  2 个评论
Darreon Schwartz
Darreon Schwartz 2017-4-12
So this provided a plot, but I do not know what to make of it, as I do not understand what your code does. What is [~,ix]? And I'm not sure what it means to plot in ascending order, or why that would be helpful.
dpb
dpb 2017-4-12
编辑:dpb 2017-4-12
I'm no image analyst so just a shot in the dark. You said had distances and intensities and wanted to plot the latter against the former but they're scattered around in an array.
So, [~,ix] just returns the position in the array of each distance in order to use in a plot that will relate whatever the intensity value represents to what each distance is.
Now, whether that means anything...that's an entirely different question. :)
Meanwhile it appears that the real Image Analyst did come along and has a klew; hopefully that is helpful. I read his code and don't know enough about the output of bwdist nor image processing as a discipline to follow it...

请先登录,再进行评论。


Image Analyst
Image Analyst 2017-4-12
I do this sometimes so I know what to do. Scan the array getting distance and gray level. Let's say your Euclidean Distance image is called edtImage and your gray scale image is called grayImage. Then do this (untested, off the top of my head)
[rows, columns] = size(edtImage);
maxDistance = sqrt(rows^2+columns^2);
profileVector = zeros(1, maxDistance); % Preallocate
countVector = zeros(1, maxDistance);
for col = 1 : columns
for row = 1 : rows
thisDistance = ceil(edtImage(row, column));
profileVector(thisDistance) = profileVector(thisDistance) + grayImage(row, column);
countVector(thisDistance) = countVector(thisDistance) + 1;
end
end
% Crop off unused elements
lastElement = find(countVector, 1, 'last');
profileVector = profileVector (1 : lastElement); % Crop
countVector = countVector(1 : lastElement); % Crop
% Convert counts to means
profileVector = profileVector ./ countVector;
% Now plot it.
plot(profileVector, 'b-', 'LineWidth', 2);
grid on;
title('Mean Gray Level vs. Distance', 'FontSize', 24);
xlabel('Distance', 'FontSize', 24);
ylabel('Mean Gray Level', 'FontSize', 24);
grid on;

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by