Plot graph with different labels

Hi,
I have a data set
y = [10,15,23];
x = {'jan','feb','mar'};
but obviously you cant plot Strings so i made a third array:
z=[1,2,3];
to represent the Strings. I would like to plot(z,y) but with x as the labels on the x axis (i dont want to see the numbers 1,2,3), how is this possible?
Also if I had 100 data points, how would i make it so only a few of the labels will be shown? thanks

 Risposta accettata

Azzi Abdelmalek
Azzi Abdelmalek il 27 Set 2013
Modificato: Azzi Abdelmalek il 27 Set 2013
y = [10,15,23];
x = {'jan','feb','mar'};
z=[1,2,3];
plot(z,y)
set(gca,'xtick',z,'xticklabel',x)

3 Commenti

Edward
Edward il 27 Set 2013
This is brilliant. Could you tell me how to make it so only a few labels show? i have 7000 elements in my x,y and z arrays so i'm just getting a black block for the label because of how close they are together
Azzi Abdelmalek
Azzi Abdelmalek il 27 Set 2013
Modificato: Azzi Abdelmalek il 27 Set 2013
Look at this example
y= [10,15,23 14 5 2 7 45 2];
x = {'jan','feb','mar' 'avr' 'mai' 'jun' 'jui' 'aou' 'sep' };
z=1:numel(y)
plot(z,y)
idxi=round(linspace(1,numel(z),5))
set(gca,'xtick',z(idxi),'xticklabel',x(idxi))
Edward
Edward il 27 Set 2013
Perfect! I dont suppose theres anyway to make this update with zooming in on the plot too?

Accedi per commentare.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by