MATLAB Answers

Plot point on image plot

17 views (last 30 days)
Ogen on 21 Mar 2016
Edited: Joachim Schlosser on 22 Mar 2016
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.')
rgb = imread('altitude4.png');
hold on
M = size(rgb,1);
N = size(rgb,2);
for k = 1:25:M
x = [1 N];
y = [k k];
for k = 1:25:N
x = [k k];
y = [1 M];
hold off
x = 0.5;
y = altitude;
ylim([0 1000])
xlim([0 1])
help plot
help hold
hold off

Answers (1)

Joachim Schlosser
Joachim Schlosser on 21 Mar 2016
Edited: Joachim Schlosser on 22 Mar 2016
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
Joachim Schlosser
Joachim Schlosser on 22 Mar 2016
Correct, you also need to specify a different xlim. I added to my answer.

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!