Plot imagesc with vector of irregular spacing
3 次查看(过去 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);
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!