Info
此问题已关闭。 请重新打开它进行编辑或回答。
Image plot I am not able to create
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I am not able to create a Image plot of the values. I have the data which represents x , y co-ordinates and corresponding velocity. A simple data file. Please find the attachment.
The image I get when generated is shown in testimg.
But the actual image would be much different, similar to that in Simi_img.
Please help.
Thank you.
0 个评论
回答(2 个)
Gareth
2018-11-23
I am using R2018b:
a=readtable('dte2.txt');
plot(a.x_coordinate,a.y_coordinate,'.')
Does this help?
0 个评论
Image Analyst
2018-11-23
编辑:Image Analyst
2018-11-23
There are certain (x,y) locations which are not present in your data so those points in the image remain unassigned.
% Import the data.
structData = importdata('dte2.txt')
x = structData.data(:, 1);
y = structData.data(:, 2);
velocity = structData.data(:, 3);
% Determine how many columns there should be in the image.
ux = unique(x);
dx = diff(ux);
subplot(2, 4, 1);
histogram(dx);
grid on;
title('Histogram of x', 'FontSize', 15);
subplot(2, 4, 2);
histogram(dx)
grid on;
title('Histogram of x spacings', 'FontSize', 15);
modeSpacing = mode(dx)
minX = min(x)
maxX = max(x)
numColumns = ceil((maxX - minX) / modeSpacing)
% Determine how many rows there should be in the image.
uy = unique(y);
dy = diff(uy);
subplot(2, 4, 3);
histogram(y)
grid on;
title('Histogram of y', 'FontSize', 15);
subplot(2, 4, 4);
histogram(dy)
grid on;
title('Histogram of y spacings', 'FontSize', 15);
modeSpacing = mode(dy)
minY = min(y)
maxY = max(y)
numRows = ceil((maxY - minY) / modeSpacing)
% Make a blank image.
velocityImage = min(velocity) * ones(numRows, numColumns);
% Turn x and y into rows and columns
xCol = round(mat2gray(x) * (numRows-1)) + 1;
yRow = round(mat2gray(y) * (numColumns-1)) + 1;
% Assign velicities.
for k = 1 : length(x)
velocityImage(yRow(k), xCol(k)) = velocity(k);
end
subplot(2,2,3);
imshow(velocityImage, [], 'XData', ux, 'YData', uy);
axis('on', 'image');
colorbar;
impixelinfo
colormap(jet(256));
% Plot the histogram of values.
subplot(2, 2, 4);
histogram(velocity, 100);
grid on;
xlabel('Velocity', 'FontSize', 15);
ylabel('Count', 'FontSize', 15);
title('Histogram of Velocities', 'FontSize', 15);
See the plot below. Only the blue dots are present in the data.
4 个评论
Image Analyst
2018-11-24
Give it a try. But if you want a solid image, I'd use scatteredInterpolant().
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!