フィルターのクリア

How to create a regular data matrix from irregularly sampled XYZ data with different X and Y coordinates

5 ビュー (過去 30 日間)
Dear, I am trying to organise my data in a matrix. The data is in the form of XYZ, where X and Y are irregular. For example a data structure like below
X Y Z
2 0 0.38
2 5 0.348
2 25 0.328
3 2 0.319
3 50 0.212
5 10 0.138
5 60 0.11
5 100 0.087
7 5 0.069
7 9 0.4113
7 45 0.3807
7 95 0.3678
9 10 0.3207
9 35 0.1765
15 65 0.1123
15 75 0.0917
15 99 0.0727
15 125 0.0573
15 150 0.3811
I have a number of Y data points for a particular X. X has a different range from Y and both has irregular intervals. I want to organize the data in a matrix, where X may be in column heading, Y may in Row heading and the matrix elements are the Z data. My target is to extract Z data for a particular X value with different Y or a particular Y with different X. Can anyone please help me. Your help is highly appreciated. Thank you so much.

採用された回答

Geoff
Geoff 2012 年 5 月 18 日
Well, I might do this:
d = [2.0000 0 0.3800;
2.0000 5.0000 0.3480;
2.0000 25.0000 0.3280;
3.0000 2.0000 0.3190;
3.0000 50.0000 0.2120;
5.0000 10.0000 0.1380;
5.0000 60.0000 0.1100;
5.0000 100.0000 0.0870;
7.0000 5.0000 0.0690;
7.0000 9.0000 0.4113;
7.0000 45.0000 0.3807;
7.0000 95.0000 0.3678;
9.0000 10.0000 0.3207;
9.0000 35.0000 0.1765;
15.0000 65.0000 0.1123;
15.0000 75.0000 0.0917;
15.0000 99.0000 0.0727;
15.0000 125.0000 0.0573;
15.0000 150.0000 0.3811];
X = d(:,1); Y = d(:,2); Z = d(:,3);
Xs = unique(X);
Ys = unique(Y);
Xi = arrayfun( @(x) find(Xs==x), X );
Yi = arrayfun( @(y) find(Ys==y), Y );
Li = Yi + (Xi-1) * numel(Ys);
XYZ = nan(numel(Ys), numel(Xs));
XYZ( Li ) = Z;
That creates a matrix where each column represents a value in Xs and each row represents a value in Ys, and the Z values are injected accordingly using linear indexing.
  2 件のコメント
Asim Biswas
Asim Biswas 2012 年 5 月 18 日
This is perfect. I was exactly looking for this. Thank you so so much. I really appreciate your time.
Thank you again. 10% percent helpful.
Asim Biswas
Asim Biswas 2012 年 5 月 18 日
sorry, 100% helpful. not 10% (mistake)

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

その他の回答 (2 件)

Andrei Bobrov
Andrei Bobrov 2012 年 5 月 18 日
[ii,i2,i2] = unique(d(:,1));
[jj,j2,j2] = unique(d(:,2));
out = [[NaN,ii'];[jj,accumarray([j2,i2],d(:,3),[],[],NaN)]]
  2 件のコメント
Asim Biswas
Asim Biswas 2012 年 5 月 18 日
Thank you so much. This is perfect and much more straight forward. Thanks again.
I appreciate your response.
Ted Rogers
Ted Rogers 2018 年 6 月 19 日
Bloody amazing. Thank you very much!

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


Steven
Steven 2014 年 3 月 7 日
編集済み: Steven 2014 年 3 月 7 日
Going through Andrei's solution, I think it is more clear to use this:
[ii,~,i2] = unique(d(:,1));
[jj,~,j2] = unique(d(:,2));

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by