Plot point on image plot

5 次查看(过去 30 天)
Ogen
Ogen 2016-3-21
Hello all, I have produced an image in photoshop. I can successful make the image (ground and sky) show in matlab however I want to plot a cross at the altitude inputted by the user. The code can be seen below. Currently the image appears (as expected) however then the image is removed to plot the cross on the same axis. I want the image to remain and the cross to be plotted above the image. Any help would be welcomed, thanks.
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,altitude,'Color','w','LineStyle','-');
plot(x,altitude,'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 off
x = 0.5;
y = altitude;
plot(x,y,'*')
ylim([0 1000])
xlim([0 1])
help plot
help hold
hold off
end

回答(1 个)

Joachim Schlosser
Joachim Schlosser 2016-3-21
编辑:Joachim Schlosser 2016-3-22
Your first
hold off
comes too early, before you actually have your final plot command. It thus wipes the pre-existing plot. Remove the first instance of the hold off command and put it at the end of your code.
Furthermore you trim your whole image too narrowly with
xlim([0 1])
Comment this out or give it some better limits.
BTW: did you ever try out MATLAB Debugger? Stepping through your code line by line immediately shows you which command results in resetting/overwriting the figure. Please check https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html
  2 个评论
Ogen
Ogen 2016-3-21
Thanks for the quick reply. This still removes the image and plots a point in the same figure but not over the image
Joachim Schlosser
Joachim Schlosser 2016-3-22
Correct, you also need to specify a different xlim. I added to my answer.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by