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
0 个评论
回答(2 个)
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 个评论
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
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;
1 个评论
Image Analyst
2017-4-13
I forgot that I already had a full demo of it. I'm attaching it now.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/184056/image.png)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!