I am plotting a matrix using below code.
The XTicklabels are supposed to be labeled per tick, but they only label every second tick.
Does anybody have a solution?
a = [12 16 5 5 5 11 4 4 3 3]; % rock data
b = [1 1 1 1 2 2 2 2 2 4]; % image data
u = union(a,b);
[~,ia] = ismember(a(:),u);
[bb,ib] = ismember(b(:),u);
n = length(u);
c = accumarray([ia(bb),ib(bb)],1,[n n]);
csum=sum(c,2);
d=c./csum;
% plot the results
figure, clf
x=u';
ytmp=flipud(u); % flip y-direction
y=cellfun(@(x) num2str(x),num2cell(ytmp),'UniformOutput',0);
pcolor(d)
colormap jet
colorbar
set(gca,'XTickLabel',num2str(x))
set(gca,'YTickLabel',y)
xlabel('Image code')
ylabel('Facies code')

8 件のコメント

Star Strider
Star Strider 2018 年 10 月 18 日
It works for me as written, labeling the ticks with the appropriate values of ‘x’ (actually ‘ytmp’), in R2018b.
If you are getting different results, post an image, and mention your MATLAB version.
Florian
Florian 2018 年 10 月 19 日
編集済み: Florian 2018 年 10 月 19 日
I use version R2018b and it does not work for me. Could you please post the entire code that your are using? Be aware that the x axis labels need to be identical to the yaxis labels both in value and distribution along the ticks.
Bruno Luong
Bruno Luong 2018 年 10 月 19 日
work just fine R2018b
Florian
Florian 2018 年 10 月 21 日
編集済み: Florian 2018 年 10 月 21 日
Hello again,
Now I tried the code on my desktop and it works without problems. When I was working on the code I used the ipad version of Matlab and there the code does not work correctly. Below I paste a screen capture of my ipad including the version of the app. It would be good if somebody could feed this back to Matlab developers.
Best regards, Florian
Bruno Luong
Bruno Luong 2018 年 10 月 21 日
"It would be good if somebody could feed this back to Matlab developers."
Any user can submit a BUG report. So you should it if you like.
Florian
Florian 2018 年 10 月 22 日
Hi Bruno, where can I submit a bug report?
Bruno Luong
Bruno Luong 2018 年 10 月 22 日
Login then go to Bug report page
But attention: this is not bug see Rik's answer about set Xtick
Rik
Rik 2018 年 10 月 23 日
Did my suggestion solve your problem? If so, please consider marking it as accepted answer. It will make it easier for other people with the same question to find an answer. If this didn't solve your question, please comment with what problems you are still having.

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

 採用された回答

Rik
Rik 2018 年 10 月 21 日

2 投票

If you want full control over the ticks, you must set both the ticks and their labels explicitly. If you don't, it may depend on your resolution if you get your desired result. You can easily check this by resizing your figure window. This has been the case since before HG2 as far as I know.
set(gca,'XTickLabel',num2str(x)),set(gca,'XTick',1:numel(x))
set(gca,'YTickLabel',y),set(gca,'YTick',1:numel(y))

3 件のコメント

Bruno Luong
Bruno Luong 2018 年 10 月 21 日
+1 I didn't notice he did not set Xtick
Rik
Rik 2018 年 10 月 21 日
The trickiest bugs to find are those where you write something on autopilot yourself and don't realize someone else didn't.
Sumiran Lohani
Sumiran Lohani 2021 年 9 月 1 日
This is a great answer. It has saved me hours of debugging thanks to your solution Rik. Thank you!

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

その他の回答 (0 件)

カテゴリ

製品

質問済み:

2018 年 10 月 18 日

コメント済み:

2021 年 9 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by