Plot imagesc with vector of irregular spacing

조회 수: 2 (최근 30일)
Ole
Ole 2023년 6월 28일
댓글: Sulaymon Eshkabilov 2023년 6월 28일
The code below reads the file.
But the plot is totally wrong in ww vector.
If I set set(gca,'ytick',[1:10:512],'yticklabel',ww(1:10:512))
would be ok. However I would like the labels at whole numbers of ww-> 490 500 510 520...
How can it be done ?
fid = fopen('a.txt','r');
s = importdata('a.txt');
fgetl(fid);
fgetl(fid);
dat = textscan(fid,'%f');
fclose(fid);
dat = dat{1};
n1 = s(1,1);
n2 = s(1,2);
max1 = s(2,2);
ww = dat(1:n1);
d = dat(n1+1:(n1+n2));
v = reshape(dat((n1+n2)+1:end)',[n1,n2])';
figure
imagesc(d,ww,v/max1);

답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 6월 28일
This is how you can get it:
s = importdata('a.txt');
D = s(3:end, 1);
n1 = s(1,1);
n2 = s(1,2);
max1 = s(2,2);
ww = D(1:n1);
d = D(n1+1:(n1+n2));
v = reshape(D((n1+n2)+1:end)',[n1,n2])';
figure
imagesc(d,ww,v/max1);
ylim([-500, -400])
  댓글 수: 2
Ole
Ole 2023년 6월 28일
편집: Ole 2023년 6월 28일
Thank you. It would look different if each pixel is set to the value ww
set(gca,'ytick',[1:10:512],'yticklabel',ww(1:10:512))
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 6월 28일
It is wrong to display 1:10:512 for the values of ww(1:10:512). Two different set of values. If one can locate the indexes to the rounded ww matching for the specified range of data and then display them, but it is a bit long story. The suggested way with axis limitations is the shortest and easiest one :)

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

카테고리

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

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by