How to create a regular data matrix from irregularly sampled XYZ data with different X and Y coordinates
Afficher commentaires plus anciens
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.
Réponse acceptée
Plus de réponses (2)
Andrei Bobrov
le 18 Mai 2012
[ii,i2,i2] = unique(d(:,1));
[jj,j2,j2] = unique(d(:,2));
out = [[NaN,ii'];[jj,accumarray([j2,i2],d(:,3),[],[],NaN)]]
2 commentaires
Asim Biswas
le 18 Mai 2012
Ted Rogers
le 19 Juin 2018
Bloody amazing. Thank you very much!
Going through Andrei's solution, I think it is more clear to use this:
[ii,~,i2] = unique(d(:,1));
[jj,~,j2] = unique(d(:,2));
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!