#### how to open a depth map from a file and transform it into a 3D point cloud – wanna convert c++ code to MATLAB script [closed]

The following c++ code snippet show how to open a depth map from a file and transform it into a 3D point cloud:

``````FILE* inFile;
fopen_s(&amp;amp;amp;inFile,"depth.txt", "rb");
fclose(inFile);

for(int i=0 ; i &amp;amp;lt; nVertices ; i++)
{
int r_i = i / (int)n_c;
int c_i = i % (int)n_c;

//normalize depth
float d_i = (float)d[i] / (float)MAX_DEPTH;
//color
vertices[i].a = 255.;
//the color of the point is a shade of gray proportional to the depth
vertices[i].b = vertices[i].g = vertices[i].r = d_i;

//calculate x-coordinate
float alpha_h = (M_PI - theta_h) / 2;
float gamma_i_h = alpha_h + (float)c_i*(theta_h / n_c);
vertices[i].x = d_i / tan(gamma_i_h);

//calculate y-coordinate
float alpha_v = 2 * M_PI - (theta_v / 2);
float gamma_i_v = alpha_v + (float)r_i*(theta_v / n_r);
vertices[i].y = d_i * tan(gamma_i_v)*-1;

//z-coordinate
vertices[i].z = d_i;

}
``````

So i wanna convert this code to a MATLAB script.
Thankss

Source: Windows Questions C++