Plotting graph over image
7 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discrete Data Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!