Azzera filtri
Azzera filtri

Plotting graph over image

12 visualizzazioni (ultimi 30 giorni)
Ogen
Ogen il 22 Mar 2016
Commentato: Ogen il 23 Mar 2016
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

Risposta accettata

Guillaume
Guillaume il 22 Mar 2016
Modificato: Guillaume il 22 Mar 2016
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 Commenti
Image Analyst
Image Analyst il 22 Mar 2016
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 il 23 Mar 2016
Thanks for your help. Would it be possible to make the star animated to produce a flashing effect?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Graphics Object Properties in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by