to build a table with XYZ values
2 views (last 30 days)
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
Star Strider on 4 Jul 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)
surf(X, Y, Z)
M = [X(:) Y(:) Z(:)] % Write This Matrix To The .CSV File
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
surf(Xr, Yr, Zr)
Image Analyst on 4 Jul 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,
% 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)
% 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)