to build a table with XYZ values

26 visualizaciones (últimos 30 días)
ELISABETTA BILLOTTA
ELISABETTA BILLOTTA el 4 de Jul. de 2022
Respondida: Image Analyst el 4 de Jul. de 2022
I have to build a table in csv format (to be used later in qgis) with 3 values of which XX = longitudes , YY = are latitudes and ZZ are the values relating to the meeting points between XX and YY.
XX is 181x151 double
YY is 181x151 double
ZZ is 181x151 double
how can I do?
thanks for the help

Respuestas (3)

Star Strider
Star Strider el 4 de Jul. de 2022
In order to save them to a file, use the (:) operator or the reshape function to create column vectors from the matrices. Concatenate those to a matrix and save them to the file using writematrix or writetable.
Use readmatrix or readtable to read the file (depending on how you saved it before), then reshape again when you read them from the file to re-create the original matrices.
Without using the actual read and write operations, that would go something like this —
[X,Y] = ndgrid(1:181,1:151);
Z = exp(-((X-90).^2+(Y-75).^2)*1E-3)
Z = 181×151
1.0e+00 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0002 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0002 0.0002 0.0002 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0002 0.0002 0.0002 0.0002 0.0002
figure
surf(X, Y, Z)
title('Original Data')
M = [X(:) Y(:) Z(:)] % Write This Matrix To The .CSV File
M = 27331×3
1.0000 1.0000 0.0000 2.0000 1.0000 0.0000 3.0000 1.0000 0.0000 4.0000 1.0000 0.0000 5.0000 1.0000 0.0000 6.0000 1.0000 0.0000 7.0000 1.0000 0.0000 8.0000 1.0000 0.0000 9.0000 1.0000 0.0000 10.0000 1.0000 0.0000
Xr = reshape(M(:,1), 181, []); % Read File & Re-Create Original Matrix
Yr = reshape(M(:,2), 181, []); % Read File & Re-Create Original Matrix
Zr = reshape(M(:,3), 181, []); % Read File & Re-Create Original Matrix
figure
surf(Xr, Yr, Zr)
title('Recovered Data')
.

dpb
dpb el 4 de Jul. de 2022
See meshgrid to build the coordinate arrays; you'll have to have the corresponding observation values from somewhere else.
Use writematrix to output the result to file as needed by the other app.

Image Analyst
Image Analyst el 4 de Jul. de 2022
Some info to build on what the other Answerers told you:
You can use either meshgrid or ndgrid - just get the arguments right.
% meshgrid and ndgrid create grids using different output formats.
% Specifically, the first two dimensions of a grid created
% using one of these functions are swapped when compared
% to the other grid format. Some MATLAB® functions use grids
% in meshgrid format, while others use ndgrid format,
a=1:4
a = 1×4
1 2 3 4
b=1:3
b = 1×3
1 2 3
% For meshgrid, think of a as x, b as y.
% Output arrays are 3 by 4, or length(b) by length(a).
[A, B] = meshgrid(a,b)
A = 3×4
1 2 3 4 1 2 3 4 1 2 3 4
B = 3×4
1 1 1 1 2 2 2 2 3 3 3 3
% For ndgrid, think of a as rows, b as columns.
% Output arrays are 4 by 4, or length(a) by length(b).
[A, B] = ndgrid(a, b)
A = 4×3
1 1 1 2 2 2 3 3 3 4 4 4
B = 4×3
1 2 3 1 2 3 1 2 3 1 2 3

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by