0

Initially I had a matrix (512x512), I created a 3d mesh using mesh() function. The figure showed me peaks. I wanted to extract the matrix for each peak and then calculate the volume. I came across two cases for the solution:

https://de.mathworks.com/matlabcentral/answers/277512-how-to-find-peaks-in-3d-mesh

Find volume of 3d peaks in matlab

In both cases the data generated in the form of X, Y, Z. This is however not my case. How can I extract matrices for each peak?

peaks from 512x512 matrix

Sultan
  • 3
  • 2

1 Answers1

0

You currently have a 2-D matrix of Z values. When you plot just the Z matrix via mesh(), MATLAB uses the row and column positions of the values in the matrix as the X and Y values. To get explicit X and Y values, you can use meshgrid(). For example, assuming your X and Y values range from 1 to 600 as shown in your linked plot:

[X, Y] = meshgrid(1:600);

Keep in mind that depending on how you want to use the Z, Y, and Z values, you may have to transform the format further. In your first link, it assumes the data is formatted as 3, 1-D arrays, while in the second link, it assumes the data is formatted as 3, 2-D matrices. If you need the values in a 1-D format, you can transform the 2-D matrices into column vectors via :, ie:

X_flat = X(:);
Y_flat = Y(:);
Z_flat = Z(:);
DMR
  • 1,479
  • 1
  • 8
  • 11