How to insert a saved .png figure into a subplot which is being created in a for loop?
43 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
hello_world
am 28 Aug. 2016
Bearbeitet: hello_world
am 28 Aug. 2016
Hello Friends,
I have the following code
for k = 1:2
subplot(1,3,k)
plot(randi(10,k));
end
I want to insert a saved .png (I prefer .png, but if it is easier for .fig, it is also ok) into this subplot which is being created in for loop at position subplot(1,3,1). This way, the inserted figure will come at the first position moving other two subfigures to the next available positions.
I will appreciate any advise!
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 28 Aug. 2016
subplot(1,3,1)
image( imread('ThePNGFile.png') );
for k = 1:2
subplot(1,3,k+1)
plot(randi(10,k));
end
See also the XData and YData properties of image() and imshow() if you want to draw an image at a particular location in an axes that has other graphics.
4 Kommentare
Walter Roberson
am 28 Aug. 2016
ax = subplot(1, 3, 1);
fig = openfig('MyFile.fig', 'visible', 'off');
imh = findobj(fig, 'type', 'image');
copyobj(imh, ax);
delete(fig);
Weitere Antworten (1)
Image Analyst
am 28 Aug. 2016
Try this:
for k = 1:3
subplot(1,3,k)
% Insert image into subplot.
filename = whatever......
thisImage = imread(filename);
imshow(thisImage);
hold on;
% Now draw the plot over it.
plot(x, y);
drawnow;
end
1 Kommentar
Siehe auch
Kategorien
Mehr zu Subplots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!