Create Categorical array for histogram on R2020a

3 次查看(过去 30 天)
It seems like this example on Histogram plot - MATLAB - MathWorks Italia :
A = [0 0 1 1 1 0 0 0 0 NaN NaN 1 0 0 0 1 0 1 0 1 0 0 0 1 1 1 1];
C = categorical(A,[1 0 NaN],{'yes','no','undecided'})
h = histogram(C,'BarWidth',0.5)
does not work on 2020a.
Any workaround?

回答(1 个)

Steven Lord
Steven Lord 2022-7-20
I tried running those three lines of code in release R2020a and it produced the categorical histogram plot that I expected.
What does "does not work" mean in this context?
  • Do you receive warning and/or error messages? If so the full and exact text of those messages (all the text displayed in orange and/or red in the Command Window) may be useful in determining what's going on and how to avoid the warning and/or error.
  • Does it do something different than what you expected? If so, what did it do and what did you expect it to do?
  • Did MATLAB crash? If so please send the crash log file (with a description of what you were running or doing in MATLAB when the crash occured) to Technical Support so we can investigate.
  1 个评论
Bruno Luong
Bruno Luong 2022-7-20
编辑:Bruno Luong 2022-7-20
Steve when I run OP code on my laptop I get this on the command window (R2022a, Windows 11, Intel Irish XE Graphic card, latest driver installed)
h =
Histogram with properties:
Data: [no no yes yes yes no no no no undecided undecided yes no no no yes no ]
Values: [11 14 2]
NumDisplayBins: 3
Categories: {'yes' 'no' 'undecided'}
DisplayOrder: 'data'
Normalization: 'count'
DisplayStyle: 'bar'
FaceColor: 'auto'
EdgeColor: [0 0 0]
Show all properties
Dot indexing is not supported for variables of this type.
Error in matlab.graphics.controls.internal.ToolbarButtonRegistry/getButtonIcon
Error in matlab.graphics.controls.AxesToolbarButton/setStandardIcon
Error in matlab.graphics.controls.AxesToolbarButton/set.Icon
Error in matlab.graphics.controls.AxesToolbarButton
Error in matlab.ui.controls.ToolbarPushButton
Error in matlab.graphics.controls.internal.PostUpdatePlugin.doCacheLoad
Error in matlab.graphics.controls.internal.PostUpdatePlugin>@()matlab.graphics.controls.internal.PostUpdatePlugin.doCacheLoad(canvasParent)
I works fine however if I do this before (may be a work around for OP)
opengl software
on other PC with different (Nvidia graphic card).
Odd and I have no ideat what to chase.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by