in plotting,instead of 'ro' its needed to show numbers

In plotting,instead of 'ro' its needed to show numbers
for example:
plot([0:20],[0:20],'ro')
its needed shows numbers from 1 up 20 instead of 'ro'
and please also refer DOC of this, I can't find it

 Respuesta aceptada

Daniel Shub
Daniel Shub el 22 de Sept. de 2011
The "o" in "ro" is not really a letter or a number. You best bet might be to use a loop and the text command ...
figure;
hold on;
axis([0, 20, 0, 20]);
for x = 0:20
h = text(x, x, num2str(x));
set(h, 'HorizontalAlignment', 'Center', 'VerticalAlignment', 'Middle');
end

5 comentarios

mohammad
mohammad el 22 de Sept. de 2011
Daniel thanks
in fact i need this for determine peaks numbers of a signal
now i have this:
figure;
plot(1:le,r,peakinds,peakmags,'ro'),ylim([0 300])
that 'r' is a matrix(10000*1)
what must be imported instead of 'ro' for showing numbers in above plotting?
Daniel Shub
Daniel Shub el 22 de Sept. de 2011
I am assuming that r is Iex1 ...
Replace plot( ... ) with
for x = 1:Ie
h = text(x, r(x), num2str(x));
set(h, 'HorizontalAlignment', 'Center', 'VerticalAlignment', 'Middle');
end
xlim([1, Ie]);
mohammad
mohammad el 22 de Sept. de 2011
No Daniel, this shows number on all all of the signals but i need showing numbers only on peak that peaks-index and peaks-values are specified in 'r' matrix that in this plot(1:le,r,peakinds,peakmags,'ro'),ylim([0 300])
red small circles are on peaks only and i need numbers also being on peaks
Daniel Shub
Daniel Shub el 22 de Sept. de 2011
Sorry, I missed that bit. After your code, you should be able to do:
for ipeak = 1:length(peakinds)
h = text(peakinds(ipeak), peakmags(ipeak), num2str(ipeak));
set(h, 'HorizontalAlignment', 'Center', 'VerticalAlignment', 'Middle');
end
mohammad
mohammad el 22 de Sept. de 2011
figure(1);
plot(1:len0,x0,peakInds,peakInds,'ro'),ylim([0 300]),xlim([2000 8500])
hold on
peakInds=peakInds(2:end);
peakMags=peakMags(2:end);
for ipeak = 1:length(peakInds)
h = text(peakInds(ipeak)+15, peakMags(ipeak), num2str(ipeak),'Color','r');
set(h, 'HorizontalAlignment', 'Center', 'VerticalAlignment', 'Middle');
end
ylim([0 400]),xlim([1000 8500])
hold off

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 22 de Sept. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by