Plot point on image plot
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
Joachim Schlosser
el 21 de Mzo. de 2016
Editada: Joachim Schlosser
el 22 de Mzo. de 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 https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html
2 comentarios
Joachim Schlosser
el 22 de Mzo. de 2016
Correct, you also need to specify a different xlim. I added to my answer.
Ver también
Categorías
Más información sobre Visual Exploration en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!