# enter values from 0 to N (imposed value) with step of 100 on the x-axis of the bar graph

2 visualizzazioni (ultimi 30 giorni)
Alberto Acri il 24 Ago 2023
Commentato: Mathieu NOE il 24 Ago 2023
Hi. I need to change the values on the x-axis of a bar graph.
I have tried in the following way but it doesn't seem to work. Why? How can I enter values from 0 to 700 (imposed value) with step of 100 on the x-axis of the bar graph?
matrix = [64 440; 65 489; 66 581; 67 563];
figure
hbh = barh(matrix(:,1), matrix(:,2));
N = 700;
step = 100;
vector_x_axis = 0:step:N;
xticks(vector_x_axis)
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Mathieu NOE il 24 Ago 2023
hello Alberto
welcome back !
i suppose you wanted to do this
matrix = [64 440; 65 489; 66 581; 67 563];
figure
hbh = barh(matrix(:,1), matrix(:,2));
N = 700;
% step = 100;
% vector_x_axis = 0:step:N;
% xticks(vector_x_axis)
xlim([0 N])
##### 4 CommentiMostra 2 commenti meno recentiNascondi 2 commenti meno recenti
Alberto Acri il 24 Ago 2023
thanks!
Mathieu NOE il 24 Ago 2023
my pleasure !

Accedi per commentare.

### Più risposte (1)

Kevin Holly il 24 Ago 2023
I'm not exactly sure what you want to see. Are one of the 3 graphs below what you want?
matrix = [64, 440; 65, 489; 66, 581; 67, 563];
N = 700;
step = 100;
vector_x_axis = 0:step:N;
figure
hbh = barh(matrix(:, 1), matrix(:, 2));
xlim([0 700])
figure
hbh = barh(matrix(:, 1), matrix(:, 2));
xticks(vector_x_axis)
xticklabels(vector_x_axis(2:end))
figure
hbh = barh(matrix(:, 1), matrix(:, 2));
xticks(vector_x_axis)
step = 700/6;
vector_x_axis = 0:step:N;
xticklabels(vector_x_axis)
##### 2 CommentiMostra NessunoNascondi Nessuno
Alberto Acri il 24 Ago 2023
Modificato: Alberto Acri il 24 Ago 2023
The final graph I want to get is the first one you showed me, BUT I want to impose on the x-axis a range taking into account both the final 'N' value (700) and the 'step' value.
For example using this code that has N=700 and step=50:
matrix = [64, 440; 65, 489; 66, 581; 67, 563];
N = 700;
step = 100;
vector_x_axis = 0:step:N;
figure
hbh = barh(matrix(:, 1), matrix(:, 2));
xticklabels(vector_x_axis)
a graph is created where the x-axis ranges from 0 to 300 (and not up to N=700) and with steps of 50
Whereas by modifying only the last line:
xticks(vector_x_axis)
In both graphs, the x-axis does not arrive at the value of 700.
Kevin Holly il 24 Ago 2023
I'm still not quite sure what you want.
matrix = [64, 440; 65, 489; 66, 581; 67, 563];
N = 700;
step = 50;
vector_x_axis = 0:step:N;
figure
hbh = barh(matrix(:, 1), matrix(:, 2));
xticks(vector_x_axis)
figure
hbh = barh(matrix(:, 1), matrix(:, 2));
xticks(vector_x_axis)
xlim([0 700])

Accedi per commentare.

### Categorie

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

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by