Plot imagesc with vector of irregular spacing

2 ビュー (過去 30 日間)
Ole
Ole 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 Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by