How to import huge irregular xyz data set from excel and create gridded matlab matrix,

2 次查看(过去 30 天)
Dear all, Completely new to matlab and would love some assistance.
I have 3 columns of data in excel, x,y,z. This data is not gridded.
x ranges from 0-1500
y ranges from 0-1500
z ranges from 0-200
Total number of rows is 150,000
I have worked out how to import this data as vectors and can see i have 3 variables in matlab, x, y and z
These are displayed individually. For example x is [150,000, 0]. y is [150,000 , 0] z is [150,000, 0] .
My question is how to i create a matrix that is gridded and assigns the z values to each pair of xy.
I then intend to plot this matrix as a contour.
The xyz data represent the surface of a concrete sample that has surface damage
x = width, y=height, z = depth
I would appreciate a complete detailed example.
I thankyou in advance for your help
Kindest Regards
Maurice

回答(1 个)

Image Analyst
Image Analyst 2014-8-31
Try this:
numbers = xlsread(filename);
x = numbers(:,1);
y = numbers(:,2);
z = numbers(:,3);
% Find max values of the data so we can scale
% to rows and columns indexes in the image we'll create.
maxx = max(x);
maxy = max(y);
% Find out how many rows (data observations) there are in the data.
numberOfRows = size(x,1);
% Define the size of the image you want to create.
columns = 800
rows = round(columns * maxy / maxy)
% Initialize an image to take the z values.
yourImage = zeros(rows, columns);
% Assign all the z values at the proper (x,y) location.
for row = 1 : numberOfRows
thisRow = 1 + round((rows-1) * x(row) / maxx);
thisColumn = 1 + round((columns-1) * y(row) / maxy);
yourImage(thisRow, thisColumn) = z(row);
end
% Display the image. Be sure to use imshow() with the [] option.
imshow(yourImage, []);

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by