how to plot matrix

Hi all,
I have 2304x1024 matrix. I assume that each 3 rows of this matrix describe an image.(so I have 768 images and each image size = 3x1024 ). And want to plot it.
Can anyone help me with this please?

Answers (2)

This code snippet extracts out the first image and plots it. Similarly you can extract the other images.
% Defining a random matrix for demo
matrix = rand(2304, 1024); % Use your matrix here
% Extract first 3 rows
image1 = matrix(1:3, :);
% Visualize
figure
imagesc(image1)

3 Comments

Thanks I can get all images using for loop .I have to display all images in a single figure.
@Fatma Nur Disci the below code might work for you
% Defining a random matrix for demo
yourMatrix = rand(2304, 1024); % Use your matrix here
% Extract all images in a cell array
imagesArray = cell(768, 1);
ind = 1;
for idx = 1:3:2304
imagesArray{ind, 1} = yourMatrix(idx:idx+2, :);
ind = ind + 1;
end
% Visualize them all in one figure
figure
montage(imagesArray, 'BorderSize', 20)
colormap parula
Thanks I tried it, just gives me one picture.
I need to see 768 images seperately in a single figure(or table, window. I don't know what it is called.).
From image1 to image 768.

Sign in to comment.

Durganshu
Durganshu on 24 Dec 2020
Edited: Durganshu on 24 Dec 2020
Let your 2304x1024 matrix be data. I'm assuming that you have to obtain these images successively in a single plot. If that is not the case, please specify how do you actually want to plot it.
for i=1:3:size(data,1)
for j=1:size(data, 2)
image(1,j) = data(i,j);
image(2,j) = data(i+1,j);
image(3,j) =data(i+2,j);
end
imagesc(image);
hold on;
end
Hope that helps!

5 Comments

Hello Deeds, I have just tried your code and get a image but did not understand what the aim of your code is. I attached that image.
I just want to get 768 images in a single figure. And every image size should be 3x1024. (These images can be grayscale format.) My whole data size 2304x1024.
I think your code plots every single row for all columns. But Suphadeep Koley's code gives me single image 3x1024 i think. I need 768 images in a single figure (using subplot maybe ?), not just one.
Yes, @Subhadeep Koley 's code extracts the first image from the data matrix and my code successively plots each image in a plot. It will plot an image and then replace it with the next image and so on. That means finally, you'll have the 768th image.
Do you want all the 768 images in a single plot ? Then the question arises, in which order do you want them? It would be good if you give a better description of what you want through a sample image.
Fatma Nur Disci
Fatma Nur Disci on 28 Dec 2020
Edited: Fatma Nur Disci on 28 Dec 2020
Order is not important . Let's assume that imagesc(1:3, 1024 ) gives the first image, imagesc(4:6,1024) describes the second one and so on.
for ind=1:768
start= (ind-1)*3+1;
stop=ind*3;
data = wholedata(start:stop,:);
imagesc(data); %%%% or pcolor(data) or %%%% I = mat2gray(data) and imshow(I)
end
When I use plot instead of imagesc I can plot multiple graphs in one figure :
figure
for ind=1:768
start= (ind-1)*3+1;
stop=ind*3;
data = wholedata(start:stop,:);
subplot(1,768,ind);
plot(data);
hold on;
end
How to plot multiple images side by side in 1x768 format in a figure for example ? Or 32x24 format in a figure?
Thanks for your help.
Hi Fatma,
Sorry for the late reply. I hope this can resolve your issue.
figure
position =1;
for ind=1:768
start= (ind-1)*3+1;
stop=ind*3;
data = wholedata(start:stop,:);
subplot(1,768,position);
imagesc(data);
hold on;
position = position+1;
end
Further, you can even use imshow and subplot for your functionality. I have never used it personally, so I'll just share the link where you can find more information on its impementation. Link!
Hope that helps!

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Asked:

on 24 Dec 2020

Commented:

on 3 Jan 2021

Community Treasure Hunt

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

Start Hunting!