How to display a few xticklabels from a set of selected xticks?
조회 수: 1 (최근 30일)
이전 댓글 표시
How to display a few xticklabels, like [4, 53] in the following example, from a set of selected xticks?
selected_ticks = [2 3 4 5 6 8 11 1 19 29 53 119];
sorted_selected_ticks = sort(selected_ticks);
plot(1:120,1:120)
xticks(sorted_selected_ticks)
Indeed, just by adding xticklabels([4 53]) after xticks(sorted_selected_ticks) I do not get what expected, i.e. tick lables in position 4 and position 53, and labelled as 4 and 53, respectively, as in the following figure (which is my desired output):
댓글 수: 0
채택된 답변
Voss
2023년 10월 31일
selected_ticks = [2 3 4 5 6 8 11 1 19 29 53 119];
selected_labels = [4 53];
sorted_selected_ticks = sort(selected_ticks);
sorted_selected_labels = sort(selected_labels);
[ism,idx] = ismember(sorted_selected_labels,sorted_selected_ticks);
assert(all(ism))
xlabels = strings(1,numel(sorted_selected_ticks));
xlabels(idx) = string(sorted_selected_labels);
plot(1:120,1:120)
xticks(sorted_selected_ticks)
xticklabels(xlabels)
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!