# Plotting 2D image with different slices in Multiple Figures by means of Loop

4 ビュー (過去 30 日間)
Amit Chakraborty 2022 年 7 月 13 日

For example I have a 3D image matrix but I want to plot it for some specific slices like following :
For 5 slices I want to draw 5 figures which will contain the 2D image of the specific slices and Intensity Profile (subplotting) and it should be plot through a LooP. Any kinds of suggestion would be appreciated.
i = 1:5; % Slice Number
RowProfile = squeeze(image3d(rowNumber, :, SliceNumber_total(i)));
img = image3d(:,:,SliceNumber_total(i));

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

### 回答 (1 件)

Siraj 2023 年 9 月 15 日
Hi! It is my understanding that you want to create a subplot that displays multiple slices of a 3D image using a for loop.
To understand how to achieve the desired result, please refer to the following code:
% Create a 3D image with random pixel values ranging from 0 to 255
image3d = randi([0 255], 1024, 1024, 5);
% Iterate over each slice of the 3D image
for i = 1:5
% Extract the current slice
img = image3d(:,:,i);
% Create a subplot with 1 row and 5 columns, and select the i-th subplot
subplot(1, 5, i)
slice_no = int2str(i);
% Display the current slice using imshow
imshow(img);
title(slice_no);
end
For displaying multiple images, there are various approaches available. You can refer to the following link that provides a detailed explanation of different methods. It will help you choose the one that best suits your task:
Hope this helps.

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

### カテゴリ

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

### Community Treasure Hunt

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

Start Hunting!

Translated by