Plot imagesc with vector of irregular spacing

1 Ansicht (letzte 30 Tage)
Ole
Ole am 28 Jun. 2023
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);

Antworten (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 28 Jun. 2023
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 Kommentare
Ole
Ole am 28 Jun. 2023
Bearbeitet: Ole am 28 Jun. 2023
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 am 28 Jun. 2023
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 :)

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by