Domanda

Whilst using Matlab's GUIDE, I wish to plot a line onto an image. I managed to achieve this when I was using only one axis inside the GUI. However upon adding another axis the plot no longer overlays the image.

Initially the plot began to plot on the wrong axis and I realized I had forgotten to set the appropriate axis. However once I had selected the image axis for plotting on, the line which is to be plotted, doesn't lie on top of the image anymore, instead it just replaces the image with a graph of the line only.

My code:

imshow(img(k),'Parent',handles.display)
hold on

x1 = line(k).point1(1);
y1 = line(k).point1(2);
x2 = line(k).point2(1);
y2 = line(k).point2(2);
plot(handles.display,[x1 x2],[y1 y2],'Color','r','LineWidth', 2)

hold off

The code before I added the new axis was identical to above but with the handles.display parameter for the plot().

Any help would be greatly appreciated, thank you in advance.

È stato utile?

Soluzione

When you call the HOLD function, you also need to specify the axis handle. Example:

%# create some axes
hAx1 = subplot(121);
hAx2 = subplot(122);

%# draw in first: image with line overlayed
I = imread('coins.png');
imshow(I, 'Parent',hAx1)
hold(hAx1,'on')
plot(hAx1, [1 100], [1 100], 'Color','r', 'LineWidth',2)
hold(hAx1,'off')

%# draw in second
surf(hAx2, peaks)

enter image description here

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top