Unable to reverse the order of numbers on the Y-axis

16 ビュー (過去 30 日間)
Chris Park
Chris Park 2018 年 5 月 22 日
コメント済み: Ameer Hamza 2018 年 5 月 22 日
plot(1,a)
bar3c(flipud(dam_tot(:,:,a)))
colorbar;
colormap(jet);
caxis([0 0.1]);
set(gca,'XTick',[1:1:11]);
set(gca,'XTickLabels',round((minSpeedRef:speed_range/(resolution-1):maxSpeedRef)));
xtickangle(-45)
set(gca,'YTick',[1:1:11]);
ax.YDir = 'reverse';
set(gca,'YTickLabels',round(flipud((minTorqueRef:torque_range/(resolution-1):maxTorqueRef))));
ytickangle(45)
xlabel('Speed');
ylabel('Torque');
title(strcat(fname{a},' Damage per Load Case'),'fontsize',14);
set(gcf,'units','inches','position',[0 .5 7 5.5])
set(gca,'FontSize',12)
  1 件のコメント
Benjamin Kraus
Benjamin Kraus 2018 年 5 月 22 日
I can't run your code without knowing more about a and dam_tot (and other variables). Setting YDir to reverse should flip the order of the numbers on the Y-axis. Can you post a screenshot of what you are seeing, and why it doesn't match what you are trying to get?

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

採用された回答

Ameer Hamza
Ameer Hamza 2018 年 5 月 22 日
編集済み: Ameer Hamza 2018 年 5 月 22 日
Your line
ax.YDir = 'reverse';
is not actually doing what you think it is doing. You should add the following line before it.
ax = gca;
ax.YDir = 'reverse';
or use set()
set(gca, 'YDir', 'reverse');
Your code is not giving an error because it is a valid MATLAB syntax. It creates a new struct object with field YDir.
  9 件のコメント
Chris Park
Chris Park 2018 年 5 月 22 日
Got it! Thank you!
Ameer Hamza
Ameer Hamza 2018 年 5 月 22 日
You are welcome.

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

その他の回答 (1 件)

Benjamin Kraus
Benjamin Kraus 2018 年 5 月 22 日
Without being able to run your code this is just speculation, but it looks like you may be double-flipping your Y-axis tick labels. Two lines of code stick out:
ax.YDir = 'reverse';
set(gca,'YTickLabels',round(flipud((minTorqueRef:torque_range/(resolution-1):maxTorqueRef))));
You have flipud in the call to set the YTickLabels, which may mean you are assigning the wrong tick labels to each tick (essentially assigning them in reverse order). Try commenting out the second line (the one that is setting YTickLabels) and see if it looks like the ticks are in the correct order. If so, remove the flipud.
  1 件のコメント
Chris Park
Chris Park 2018 年 5 月 22 日
I tried comment out the line you recommended but it did not work. I have attached an image of the graph I am getting. I would like to reverse the order of the y-axis numbers (torque)

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

カテゴリ

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

タグ

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by