Filter löschen
Filter löschen

How can I make the x and y labels start at the origin?

16 Ansichten (letzte 30 Tage)
Al Gut
Al Gut am 28 Jan. 2021
Bearbeitet: Al Gut am 29 Jan. 2021
This is my code to plot a matrix with imagesc:
imagesc(f);
set ( gca, 'ydir', 'normal' )
colorbar
ticks=[0:12.5:100];
xticks(ticks);
xticklabels({100:100:800});
yticks(ticks);
yticklabels({10:10:80});
--- I want the axis to start in the origin with x=100 and y=10 but it start to write labels one xtick later. How can I fix that? I want to have my first tick label in the origin and with a value of x=100, y=10.

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 28 Jan. 2021
The issue is that you are specifying your first tick to be at 0. Image X and Y values come from the column and row indices of the array, respectively. MATLAB does not use an index of 0. It starts at 1. Therefore, your first tick is getting skipped. Start your ticks at one instead.
Also note that you have specified 9 tick locations but only 8 labels.
Z = 10 + peaks(100);
imagesc(Z)
set ( gca, 'ydir', 'normal' )
colorbar
ticks=linspace(1,100,8);
xticks(ticks);
xticklabels({100:100:800});
yticks(ticks);
yticklabels({10:10:80});

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by