This question is closed. Reopen it to edit or answer.

Image plot I am not able to create

1 view (last 30 days)
Kushal Kumar
Kushal Kumar on 23 Nov 2018
Closed: MATLAB Answer Bot on 20 Aug 2021
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.

Answers (2)

GT on 23 Nov 2018
I am using R2018b:
Does this help?

Image Analyst
Image Analyst on 23 Nov 2018
Edited: Image Analyst on 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 =, 1);
y =, 2);
velocity =, 3);
% Determine how many columns there should be in the image.
ux = unique(x);
dx = diff(ux);
subplot(2, 4, 1);
grid on;
title('Histogram of x', 'FontSize', 15);
subplot(2, 4, 2);
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);
grid on;
title('Histogram of y', 'FontSize', 15);
subplot(2, 4, 4);
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);
imshow(velocityImage, [], 'XData', ux, 'YData', uy);
axis('on', 'image');
% 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.
0001 Screenshot.png
Kushal Kumar
Kushal Kumar on 24 Nov 2018
I have tried, ScatteredInterpolant() with nearset alogrithm. However, I am able to get points and variables but not able to access them for the plot.
May I know how can I plot. I think I am going in circles.


Community Treasure Hunt

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

Start Hunting!

Translated by