Making a function to restructure matrix of coordinates

I have a 36x3 matrix of data in a double, where the three columns represent x, y, and z coordinates. I'm trying to make two functions. The first will restructure the matrix so that it becomes a 6x6 data set, where the column and row numbers represent the x and y values and the cells represent the z values. The second reverses this, and converts the 6x6 back into the original 36x3. I've looked a bit into using the reshape function, but I dont know how to incorporate the values of the rows and columns. Any help is appreciated. Thanks.

2 件のコメント

James Tursa
James Tursa 2020 年 4 月 13 日
Your 6x6 scheme can only work if the x and y values form a regular grid and the formula for the grid coordinates is known. Is that the case? If so, how is the data in the 36x3 matrix organized? Can you give a numeric example?
Patrick O'Mahony
Patrick O'Mahony 2020 年 4 月 14 日
They form a regular grid, yes. They're listed row by row of the regular grid, I hope this example helps to visualize it.
x y z
1 1 12
2 1 13
3 1 13
4 1 14
5 1 13
6 1 14
1 2 14
2 2 15
3 2 13
4 2 12
5 2 14
6 2 17
....

サインインしてコメントする。

 採用された回答

Matt J
Matt J 2020 年 4 月 14 日
編集済み: Matt J 2020 年 4 月 14 日

0 投票

Z=reshape(xyz(:,3),6,6); %6x6 format
and then to revert back,
[X,Y]=ndgrid(1:6);
xyz=[X(:),Y(:),Z(:)]; %36x3 format

3 件のコメント

Patrick O'Mahony
Patrick O'Mahony 2020 年 4 月 14 日
That works, thanks!
Matt J
Matt J 2020 年 4 月 14 日
You're welcome. Please Accept-click th answer, though, to indicate that a solution was reached for you.
Patrick O'Mahony
Patrick O'Mahony 2020 年 4 月 14 日
Sorry, I tried earlier but it keeps repeating an error message even after reloading.
"Unable to complete the action because of changes made to the page. Reload the page to see its updated state."

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTime Series Objects についてさらに検索

製品

リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by