Plotting graph over image

12 次查看(过去 30 天)
Ogen
Ogen 2016-3-22
评论: Ogen 2016-3-23
Hello all I have plotted an image on matlab. I have another plot of a single cross that I want to appear over the image at the height inputted by the user. The code can be seen below. Currently the image appears then disappears for the cross to be plotted in the same figure window however I want the image to remain and the cross to appear on the image. I think it could be an issue with 'hold off' but I have tried this and can't crack the problem, any help would be greatly appreciated.
if true
altitude = 'Please enter the altitude in metres you wish to detonate: ';
altitude = input(altitude);
if (altitude<=100);
disp('This is an aerial burst estimator, please enter a number greater than 100 metres.')
elseif (altitude>100000);
disp('The Test Ban Treaty of 1963 prohibits nuclear weapons tests "or any other nuclear explosion"')
disp('in the atmosphere, in outer space, and under water.')
return
end
clf
rgb = imread('altitude4.png');
imshow(rgb)
hold on
M = size(rgb,1);
N = size(rgb,2);
for k = 1:25:M
x = [1 N];
y = [k k];
plot(x,y,'Color','w','LineStyle','-');
plot(x,y,'Color','k','LineStyle',':');
end
for k = 1:25:N
x = [k k];
y = [1 M];
plot(x,y,'Color','w','LineStyle','-');
plot(x,y,'Color','k','LineStyle',':');
end
hold
x = 0.5;
y = altitude;
plot(x,y,'*')
ylim([0 750])
xlim([0 1])
ylabel('Altitude (meters)');
help hold
end

采纳的回答

Guillaume
Guillaume 2016-3-22
编辑:Guillaume 2016-3-22
By default, plot delete existing objects (image, other plots, etc.) from the axes. To turn that behaviour off you must have hold set to 'on' every time you plot.
Note that issuing just
hold
toggles the state of hold. As posted your code is:
%...
imshow(rgb)
hold on
%... several plots in a loop that are going to be plotted on top of the image
% since hold is on
hold %TOGGLE THE STATE OF HOLD! so new plot erase content
%...
plot(x, y, '*') %erase content of axes since hold is off
Solution: get rid of the single hold before you plot your altitude.
There's also the problem that you change the xlim to [0 1] which will result in the axes only showing one column of your image. There is no need for you to change xlim or ylim.
  9 个评论
Image Analyst
Image Analyst 2016-3-22
Tom: If it's working you can "Accept" and vote for Guillaume's answer to "thank" him by giving him reputation points.
If you still need help, post a screenshot so we can see what you're talking about better.
Ogen
Ogen 2016-3-23
Thanks for your help. Would it be possible to make the star animated to produce a flashing effect?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Properties 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by