How to change the imagesc axis?

조회 수: 263 (최근 30일)
Kalasagarreddi Kottakota
Kalasagarreddi Kottakota 2023년 3월 10일
편집: Simon Chan 2023년 3월 10일
I have he following code which displays imagesc axis with the length of the samples. But I want the x axis to be dispyed w.r.t time t. Can some one help me regarding this?
clear all; close all;
t= 0:0.1:1;
N = length(t);
M = randn(N,N);
figure()
imagesc(M);

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 3월 10일
You can specify the x and y ranges and then add ticks for all values of t
t= 0:0.1:1;
N = length(t);
M = randn(N,N);
figure()
imagesc([t(1) t(end)], [1 N], M)
xticks(t)

추가 답변 (1개)

Simon Chan
Simon Chan 2023년 3월 10일
Use function xticklabels
clear all; close all;
t= 0:0.1:1;
N = length(t);
M = randn(N,N);
figure()
imagesc(M);
ax=gca;
xticklabels(ax,t(ax.XTick));
  댓글 수: 2
Kalasagarreddi Kottakota
Kalasagarreddi Kottakota 2023년 3월 10일
this works okay, but lets say t = 0:1/6:1, then axis looks this. Is there any way to set the xticks more properly instead of 0.16, 0.33. etc. I am looking more like 0.25, 0.5,0.75,1..etc
clear all; close all;
t= 0:1/6:1;
N = length(t);
M = randn(N,N);
figure()
imagesc(M);
ax=gca;
xticklabels(ax,t(ax.XTick));
Simon Chan
Simon Chan 2023년 3월 10일
편집: Simon Chan 2023년 3월 10일
Suppose you would like to roundoff to 2 decimal places.
clear all; close all;
t= 0:1/6:1;
N = length(t);
M = randn(N,N);
figure()
imagesc(M);
ax=gca;
xticklabels(ax,round(100*t(ax.XTick))/100);
Or if you want to show all TickLabels to have 2 decimal places.
figure()
imagesc(M);
ax=gca;
xticklabels(ax,compose('%.2f',round(100*t(ax.XTick))/100));

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by