Effacer les filtres
Effacer les filtres

imshow produces error when used in subplot

1 vue (au cours des 30 derniers jours)
F Sp
F Sp le 6 Juin 2020
Commenté : F Sp le 7 Juin 2020
Hello,
I had a working code using:
figure, imshow(I);
Then I wanted to put all the displayed images into one figure using subplot in this way:
figure;
h = [];
h(1) = subplot(2,4,1); etc.
and calling the image via:
imshow(I,'Parent', h(2))
The problem is that this now produces the error:
"Unable to perform assignment because dot indexing is not supported for variables of this type.
Error in images.internal.basicImageDisplay (line 78)
ax_handle.Colormap = map;
Error in imshow (line 330)
hh = images.internal.basicImageDisplay(fig_handle,ax_handle,..."
Also the image now appears blue and yellow instead of black and white.
Being new to MatLab I can only assume something went wrong with the colormap interfering with multiple images in one figure.
Any help would be appreciated a lot :)

Réponse acceptée

Ameer Hamza
Ameer Hamza le 6 Juin 2020
From your code, it is not clear how did you assign the 2nd element of vector h. However, I recommend initializing 'h' with 'gobjects'.
Replace
h = [];
with
h = gobjects;
  3 commentaires
Image Analyst
Image Analyst le 6 Juin 2020
What page gave that incorrect information? Not this one.
F Sp
F Sp le 7 Juin 2020
somewhere on MatLab Answers, of course not in this particular question. Thank you guys

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 6 Juin 2020
Modifié(e) : Image Analyst le 6 Juin 2020
You do not need to initialize h to anything, not [] nor gobjects. This works perfectly fine:
figure;
h = []; % Unnecessary.
h(1) = subplot(2,4,1);
% and calling the image via:
I = imread('peppers.png');
imshow(I,'Parent', h(1))
Just make sure you haven't assigned h to anything in advance, like h is not already a cell array or structure or some other complicated non-numerical variable. If h does already exist when you get to h=[], then it might be a mistake to use the same variable h because setting it to null would blow it away and if you ever needed that original h again you would not have it anymore.
Just make sure whatever index you're using in h exists, like you can't use h(2) if you haven't called h(2) = subplot yet.
  1 commentaire
F Sp
F Sp le 6 Juin 2020
Thank you too! :)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Object Programming dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by