Image plot I am not able to create
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
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.
Antworten (2)
Gareth
am 23 Nov. 2018
I am using R2018b:
a=readtable('dte2.txt');
plot(a.x_coordinate,a.y_coordinate,'.')
Does this help?
Image Analyst
am 23 Nov. 2018
Bearbeitet: Image Analyst
am 23 Nov. 2018
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 Kommentare
Image Analyst
am 23 Nov. 2018
Maybe you should try scatteredInterpolant().
Kushal Kumar
am 24 Nov. 2018
Image Analyst
am 24 Nov. 2018
Give it a try. But if you want a solid image, I'd use scatteredInterpolant().
Kushal Kumar
am 24 Nov. 2018
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!