x data sorting in stem plot

How can I keep the same x data sorting (categorical array) in a stem plot?

4 件のコメント

darova
darova 2020 年 5 月 26 日
Please explain more, attach the code. Show some pictures
Manuel Di Luigi
Manuel Di Luigi 2020 年 5 月 26 日
I would to keep the same order of the categorical array (redbox on the side) along the x-axis on the chart.
stem(categorical(C),D,'Filled','Markersize',10);
darova
darova 2020 年 5 月 26 日
Try manually change xticklabel
h = stem(...);
set(h,'xticklabel',[1 2 3])
Manuel Di Luigi
Manuel Di Luigi 2020 年 5 月 26 日
Unfortunately I have already tried ... it doesn't work!

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

回答 (1 件)

Cris LaPierre
Cris LaPierre 2020 年 5 月 26 日
編集済み: Cris LaPierre 2020 年 5 月 26 日

0 投票

By default, Categoricals are organized in alphanumeric order. If you want to impose your own order on them, use the reordercats function. Since we don't have your code or files, here's a simple example using the months of the year.
month = ["January","February","March","April","May","June","July","August","September","October","November","December"];
m = categorical(month);
% Show order of categories (alpha-numeric)
categories(m)
ans = 12×1 cell array
'April'
'August'
'December'
'February'
'January'
'July'
'June'
'March'
'May'
'November'
'October'
'September'
m = reordercats(m,month);
% Show updated order of categories (imposed order)
categories(m)
ans = 12×1 cell array
'January'
'February'
'March'
'April'
'May'
'June'
'July'
'August'
'September'
'October'
'November'
'December'

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

質問済み:

2020 年 5 月 26 日

編集済み:

2020 年 5 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by