Plot imagesc with vector of irregular spacing

1 次查看(过去 30 天)
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
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
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