MATLAB: Imshow produces error when used in subplot

colormapimshowMATLAB and Simulink Student Suitesubplot

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 🙂

Best Answer

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;