How do I flip an image without affecting the Y Axis?

10 ビュー (過去 30 日間)
Ted Baker
Ted Baker 2020 年 7 月 21 日
コメント済み: Ted Baker 2020 年 7 月 21 日
I'm trying to plot the example file using the following code:
close all;
input = 'example.txt';
data = readmatrix(input);
filename = input(1:end-4);
filename = [filename '.png'];
x = data(:,3);
v = data(:,9);
id = find(x == 0);
imdata = reshape(v,id(2)-1,[])';
im = rot90(imdata,2);
im = fliplr(im);
xdata = 1:1:56;
ydata = 6.3:0.275:19.775;
flip(ydata);
imagesc(im, 'XData', xdata, 'YData', ydata);
colorbar;
colormap(jet);
xlabel('xaxis');
ylabel('yaxis');
title('title');
axis on
xticks(xdata);
set(gca, 'XTick', (1 : 5 : 56) );
yticks(ydata);
set(gca, 'YTick', (6.3: 1.375 :19.775) ); % plot every 5th tick
set(gca,'YDir','normal')
Where I would like the red corner of the output plot in the top right, blue corner in bottom left, as per this image:
However the Y axis nees to go from ~6 in the bottom left to ~19 in the top left - the axis in this image are reversed. What am I doing wrong with my code? I've tried using ydata straight, flipping it, etc but that hasn't worked. Whenever I set YDir it always flips the image so that the red in at the bottom, but then the axis looks ok.
Thanks in advance.

採用された回答

Mehmed Saad
Mehmed Saad 2020 年 7 月 21 日
編集済み: Mehmed Saad 2020 年 7 月 21 日
Use flip (or fliplr,flipud)
figure,
subplot(211)
imagesc(im, 'XData', xdata, 'YData', ydata);set(gca,'YDir','normal')
subplot(212)
imagesc(im, 'XData', xdata, 'YData', fliplr(ydata));set(gca,'YDir','normal')
colormap('jet')
  1 件のコメント
Ted Baker
Ted Baker 2020 年 7 月 21 日
Thank you very much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by