to build a table with XYZ values
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (3)
Star Strider
am 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)
figure
surf(X, Y, Z)
title('Original Data')
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
figure
surf(Xr, Yr, Zr)
title('Recovered Data')
.
0 Kommentare
Image Analyst
am 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,
a=1:4
b=1: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)
% 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)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!