x data sorting in stem plot

조회 수: 1 (최근 30일)
Manuel Di Luigi
Manuel Di Luigi 2020년 5월 26일
편집: Cris LaPierre 2020년 5월 26일
How can I keep the same x data sorting (categorical array) in a stem plot?
  댓글 수: 4
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일
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'

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by