how can I reshape and display all the images from matrix
Mostra commenti meno recenti
Hi I have a matrix 16896x1536 double this matrix contains of 33 color images of size 512x512. I used the code below to reshape and display all the images but I have this error
Error using reshape To RESHAPE the number of elements must not change.
This is my code
figure
colormap(gray)
for i = 1:33
subplot(5,5,i)
digit = reshape(a(i, 2:end), [28,28])';
imagesc(digit)
title(num2str(a(i, 1)))
end
1 Commento
Rik
il 22 Set 2017
Have you even thought of reading the documentation? I don't understand how people can use a function, get an error, and then ask a question here before reading the documentation. The error message already gives you the answer: you cant change the shape (reshape) a matrix and change the number of elements at the same time.
How exactly does the master matrix contain your images? I would advise you to convert it to a 512x512xcolorximage sized matrix. Then your code will be much more clear.
Risposte (1)
I have absolutely no idea why you're trying to reshape something into a 28x28 matrix in your loop, nor why you iterating for 1 to 33 when you tell us your input 16896x1536.
Assuming that your extremely badly named a is your 16896x1536 matrix, this may work:
stackedimages = reshape(a, 512, 512, 3, 33);
You may have to permute the order of the 512s, 3 and 33 as you've not stated how the images are arranged into your wrongly shaped matrix. Once it is correct:
for imageindex = 1:33
subplot(5, 7, imageindex) %note that 5x5 is only room for 25 images, so using 5x7)
digit = stackedimage(:, :, :, imageindex); %depending on the permutation imageindex may be 1st, 2nd, 3rd or 4th dimension
imagesc(digit);
title(sprintf('image %d', imageindex));
end
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!