i want to create a figure using imagesc for a 3D coordination system.

9 views (last 30 days)
Hello there,
i'm currently working on a code to generate an images using the function imagesc. in fact, i define the coordinate of my images in 2D as you can see in the attached figure by imcrop. The code works well in 2D when the coordinates were only x & y. However, when i added the third coordinate z in order to obtain a third image representing the field out of plane, i have get the following errors in the input of my coordination system.
In fact, i want to create a third figure representing the displacement map according to z-axis.
Thank you for your answers,

Answers (1)

Hitesh
Hitesh on 7 Mar 2025
Edited: Hitesh on 1 Apr 2025
Hi Rafik,
The error you are encountering is due to "imcrop" function, which expects a rectangle defined by four elements: [xmin, ymin, width, height]. Based on the image you've attached, its clear that you are attempting to use "imcrop" for a 3D crop operation. However, "imcrop" is designed for 2D data and doesn't directly support 3D data.
To handle 3D data, you need to use indexing.
  1. 2D Crop for Each Slice: If you want to crop each 2D slice in the 3D volume, you need loop through each slice and apply "imcrop".
  2. Indexing for 3D Crop: Use MATLAB indexing to crop the 3D data directly.
  3. Replace the dimensions and indices with the ones specific to your data. Adjust the depth variable to match how much of the z-axis you want to include.
Kindly refer to the following example piece of code for better understanding:
% Crop the 3D data using indexing
croppedData = data(xmin:xmin+width-1, ymin:ymin+height-1, zmin:zmin+depth-1);
% Display one slice using imagesc
imagesc(croppedData(:,:,1)); % Display the first slice

Community Treasure Hunt

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

Start Hunting!