to build a table with XYZ values
조회 수: 21 (최근 30일)
이전 댓글 표시
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
답변 (3개)
Star Strider
2022년 7월 4일
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
Image Analyst
2022년 7월 4일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!